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 ?
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 !!!
The package you will need can be installed using the following commands (on Debian Lenny):
apt-get install build-essential apt-get install cmake apt-get install pkg-config apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2 apt-get install zlib1g-dbg zlib1g zlib1g-dev apt-get install libjasper-dev libjasper-runtime libjasper1 apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev apt-get install libxine1-ffmpeg libxine-dev libxine1-bin apt-get install libunicap2 libunicap2-dev apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils apt-get install swig apt-get install libv4l-0 libv4l-dev apt-get install python-numpy
- Not all those packages are necessarily needed. CMAKE will show you what you have installed.
For adding other features such as CUDA or a GUI (gtk+ 2.X or Qt), refer to the InstallGuide.
- You might have to be logged in as root or use "sudo apt-get" instead of "apt-get" in all the commands mentioned above.
- If you also want to use OpenCV from Python, add this:
apt-get install libpython2.6 python-dev python2.6-dev # Only if you want to use python
If your system has trouble with building "libjpeg.so", you may need to build it manually, or try this:
apt-get install libjpeg-progs libjpeg-dev
- On Ubuntu 10.10 this apt-get was needed to recognize gstream-app and gstreamer-vid development headers
apt-get install libgstreamer-plugins-base0.10-dev
Getting the latest stable OpenCV version
- Windows: download the executable installation package for Windows and run it
- Linux/MacOSX/other operating systems: download the source tarball and unpack it
Getting the cutting-edge OpenCV from SourceForge SVN repository
- Launch SVN client and checkout either
the current OpenCV snapshot from here: https://code.ros.org/svn/opencv/trunk
or the latest tested OpenCV snapshot from here: https://code.ros.org/svn/opencv/tags/latest_tested_snapshot
- In Linux it can be done using command line, e.g.:
cd ~/<my_working_directory svn co https://code.ros.org/svn/opencv/trunk
Building OpenCV from source using CMake, using the command line
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.
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
a. Enter the created temporary directory (<cmake_binary_dir>) and run make utility. Then you can run "sudo make install" :
make sudo make install
If you did not want to run "make install", refer to the InstallGuide
Making Python work
Try to run
$ python2.6 Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) [GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cv
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):
- move the cv.so file from the site-packages to the dist-packages :
sudo mv /usr/local/lib/python2.6/site-packages/cv.so /usr/local/lib/python2.6/dist-packages/cv.so
- add to /usr/local/lib/python2.6/dist-packages os.path in python :
>>>import sys >>>print sys.path >>>sys.path.append("/usr/local/lib/python2.6/site-packages")
- Using bash : export $ PYTHONPATH=/usr/local/lib/python2.6/site-package. Add this line to your ~/.bashrc if you want it to be permanent.
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.
- 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 ..
- 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
- Thanks to Gijs Molenaar, who help me to solve this problem on the OpenCV User Group. It is on his impulsion that I wrote this page.