OpenCV Installation Guide on Debian and Ubuntu

Here you will get a step by step compilation guide for GNU/Linux Debian Squeeze and *Ubuntu.

Why compiling ?

You can not use the python-opencv package because he provide old python support (for more information, check this bug report.).On Ubuntu, python bindings won't work (check this bug report)

So you must use the compilation. But there is also some trouble with the compilation : python bindings don't work (In fact, it is the same problem as Ubuntu, so ubuntu user can install OpenCV with their package manager, and then directly go to the Making Python work section).

There is also some more info on the Linux Install Guide for OpenCV. Good Luck !!!

Prerequisites

Package needed

The package you will need can be installed using the following commands (on Debian Lenny):

Notes:

    apt-get install libpython2.6 python-dev python2.6-dev  # Only if you want to use python

    apt-get install libjpeg-progs libjpeg-dev

    apt-get install libgstreamer-plugins-base0.10-dev

Getting the latest stable OpenCV version

Getting the cutting-edge OpenCV from SourceForge SVN repository

Building OpenCV from source using CMake, using the command line

  1. Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries.

  2. a. Enter the <cmake_binary_dir> and type

    •     cmake [<some optional parameters...>] <path to the OpenCV source directory>
      For example, if you downloaded the project to ~/opencv, you can do the following:
          cd ~/opencv # the directory containing INSTALL, CMakeLists.txt etc.
          mkdir release
          cd release
          cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

That will generate makefiles for the Release configuration and will put them in ~/opencv/release directory. If you want tu use special features such as IPP or TBB, please refer to the InstallGuide

  1. a. Enter the created temporary directory (<cmake_binary_dir>) and run make utility. Then you can run "sudo make install" :

    •     make
          sudo make install
  2. If you did not want to run "make install", refer to the InstallGuide

Making Python work

Try to run

Python may return to you an error like "No module named cv" The trouble is that the python module is installed in /usr/local/lib/python2.6/site-packages. But, on Debian and on Ubuntu, Python only looks in /usr/local/lib/python2.6/dist-packages

You can fix it using three ways (Use only one of those, the first is the best):

If you don't have root privilege

If you don't have root privilege, you are not allowed to install your compiled Opencv in the system directories. You thus need to modify a bit the installation procedure detailed above.

  1. Change the installation directories by modifying the CMAKE_INSTALL_PREFIX variable. So the cmake command might look like

cmake -D CMAKE_INSTALL_PREFIX=/home/your_login/opt/opencv_intall -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
  1. You still have to tell python where is the cv.so file, but you also have to change the current working directory to where all libopencv_*.so are. So, importing opencv may become:

>>>import sys,os
>>>sys.path.append("/home/your_login/opt/opencv_intall/lib/python2.6/site-packages")
>>>os.chdir('/home/your_login/opt/opencv_intall/lib')
>>>import cv


OpenCV Wiki

Full OpenCV Wiki

OpenCVWiki: InstallGuide : Debian (last edited 2011-07-03 17:30:31 by digikata)