Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

Why cv2.so missing after opencv installed?

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...