Installing OpenCV from Source (Subversion) with Python Support on Ubuntu

    _   _              _    ___  _            _     _                  _
   /_\ | |_ __  ___ __| |_ / _ \| |__ ___ ___| |___| |_ ___   _ _  ___| |_
  / _ \| | '  \/ _ (_-<  _| (_) | '_ (_-</ _ \ / -_)  _/ -_)_| ' \/ -_)  _|
 /_/ \_\_|_|_|_\___/__/\__|\___/|_.__/__/\___/_\___|\__\___(_)_||_\___|\__|
                                                   In Glorious ASCII-VISION
Home

2010-06-23 Wed Installing OpenCV from Source (Subversion) with Python Support on Ubuntu

THIS IS ALMOST CERTAINLY OUT OF DATE NOW, I'D RECOMMEND YOU CHECK OUT THE OFFICIAL INSTRUCTIONS.

Another page for Google, I hope someone finds it useful.

This is how I got OpenCV installed and capturing video from the built in wbcam on my laptop. Before using this you might want to check out the install guide wiki page and the Linux install guide wiki page and Debian install guide on the OpenCV Wiki. There are also prebuilt packages for ubuntu that may work fine for you, I found that webcam capture failed with those packages but that may just be my system.

This is just what worked for me so it may be incomplete.

Install steps

  1. Install required packages using apt-get
sudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev
sudo apt-get install libpng3 libpnglite-dev ibpngwriter0-dev libpngwriter0c2
sudo apt-get install zlib1g-dbg zlib1g zlib1g-dev libjasper-dev 
sudo apt-get install libjasper1 pngtools libtiff4-dev libtiff4 libtiffxx0c2 
sudo apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog ffmpeg
sudo apt-get install libavcodec-dev libavcodec52 libavformat52 libavformat-dev
sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0
sudo apt-get install libxine1-ffmpeg libxine-dev libxine1-bin
sudo apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils
sudo apt-get install swig libv4l-0 libunicap2 libunicap2-dev
sudo apt-get install libgstreamer0.10-dev libtiff-tools
sudo apt-get install libjasper-runtime libv4l-dev python-numpy
sudo apt-get install libpython2.6 python-dev 
  1. Checkout the latest code from SVN
svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk opencv
  1. Create a release directory and cd into it
cd opencv
mkdir release
cd release
  1. Run cmake to create the Makefile
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON  -D USE_TBB=ON -D BUILD_EXAMPLES=ON -Wno-dev  ..   

Check that there are no errors in the output of cmake. For me it complained that gstreamer-app-0.10 and gstreamer-video-0.10 were not found but this didn't seem to cause any problems.

  1. Run make then "make install"
make 
sudo make install

This should install the cv.so library in usr/local/lib/python2.6/site-packages. But this location isn't in the Python path in Ubuntu with Python >= 2.6 so we need to move it.

  1. Move cv.so to the correct location.
sudo mv /usr/local/lib/python2.6/site-packages/cv.so /usr/local/lib/python2.6/dist-packages/cv.so

You should now be able to "import cv" from Python. Remember that this is the new Python wrapper, if you see code with "import opencv" or "from opencv import cv" or that prefixes function names with "cv" then you're looking at code for the old wrapper.

 __________________
< made in Org-mode >
 ------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                 |   | ----w |
                 ||     ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Author: Thomas Parslow

Date: 2011-01-31 16:31:19 GMT

HTML generated by org-mode 7.01trans in emacs 23