Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cv2.so missing after opencv installed?

Tags:

Today I installed opencv 2.4.4 to Ubuntu 12.10

But import cv2 not works.

root@-:~# python Python 2.7.3 (default, Sep 26 2012, 21:53:58)  [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 Traceback (most recent call last):   File "<stdin>", line 1, in <module> ImportError: No module named cv2 >>>  

As I understand cv2.so missed, so python don't see where opencv

root@-:~# find / -name "cv.py" /root/opencv-2.4.4/modules/python/src2/cv.py root@-:~# find / -name "cv2.so" root@-:~# 

My setup steps look like

wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.4/OpenCV-2.4.4a.tar.bz2 tar -xjf OpenCV-2.4.4a.tar.bz2 cd opencv-2.4.4 mkdir release cd release  cmake -D CMAKE_BUILD_TYPE=RELEASE   -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON .. make && make install echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf ldconfig   echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc 

Where is cv2.so ? And why it was missed ?

like image 235
Alex Avatar asked Apr 03 '13 14:04

Alex


People also ask

Why cv2 is not found?

The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.

Is cv2 part of OpenCV?

cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.

Does OpenCV-Python have cv2?

cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python".

Where is cv2 so?

The file cv2.so is stored in /usr/local/lib/python2. 7/site-packages/... There are also folders in /usr/local/lib called python3. 2 and python2.


2 Answers

How to install opencv(cv2) with python bindings in Linux - Ubuntu/Fedora

  1. Install gcc, g++/gcc-c++, cmake (apt-get or yum, in case of yum use gcc-c++)

    apt-get install gcc, g++, cmake 
  2. Downlaod latest opencv from openCV's website

  3. Untar it with

    tar -xvf opencv-* 
  4. Inside the untarred folder make a new folder called release

    mkdir release cd release 

    (or any folder name) and run this command in it

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. 

    the .. will pull files from the parents folder and will get the system ready for installation on your platform.

  5. in the release folder run

    make 
  6. After about 2-3 mins of make processing when its finished run

    sudo make install 
  7. Export python path

    export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages 

That's it, now go to python and try

>>> import cv2 

you should not get any error message.

Tested on python 2.7, should be virtually similar to python 3.x.

like image 79
Waqas Avatar answered Sep 22 '22 22:09

Waqas


I install python-opencv to solve my problem in Ubuntu 14.04 sh sudo apt-get install python-opencv

like image 30
Wei Yang Avatar answered Sep 23 '22 22:09

Wei Yang