简体   繁体   中英

Installation of OpenCV in Ubuntu 14.04

I built OpenCV from Source but I can't manage to use it. Every time I try to even load an image with the next code I get No module named cv2.cv . Why is that happening? How can I fix it?

from cv2.cv import *

img = LoadImage("/home/User/Desktop/Image.png")
NamedWindow("opencv")
ShowImage("opencv",img)
WaitKey(0)

The procedure I did was the following...

I downloaded the zip file from the main page of GitHub and while being in a destination directory I created, I built OpenCV using

cmake OpenCV_Source_Directory

Then on the destination directory I run

make

sudo make install

I found the solution to my problem. I had to install python-opencv as follows:

sudo apt-get install python-opencv

After that OpenCV works fine.

You've likely installed opencv 3, which doesn't have the cv2.cv module. It's all in cv2 now.

To verify run this in a python interpreter

import cv2
print cv2.__version__ 

Anything like 3.0.0 or 3.1.0 means that the cv2.cv module doesn't exist.

Presumable you did:

git clone git@github.com:opencv/opencv.git
mkdir build; cd build
cmake ../opencv && make && sudo make install

But if you do this:

cd opencv
git describe

You will get something like

3.1.0-1374-g7f14a27

That is, the default branch is OpenCV 3, which doesn't have the cv2.cv module. Either change your code to work with the OpenCV 3 cv2 module. Or downgrade to OpenCV2. You can do this by:

cd opencv
git checkout 2.4.13.1
cd ../build && so on ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM