Compiling OpenCV for Linux (Debian)

I am sure that most of you know OpenCV, the open-source Computer Vision library initially developed by Intel.

Synaptic, the packages manager of all Debian based distributions  do contain opencv packages (namely libcv, libcvaux and libhighgui). But they are seriously outdated (2.1 in Ubuntu 11.10 when the last stable release on sourceforge is the 2.3.1a).

If you want to use some new features (such as the new Python bindings in my case), you will have to compile OpenCV by yourself.

An excellent install guide for Debian is available on the OpenCV Wiki. Do not forget to install libgtk2.0 too if you want to use screen display functions later.

{% highlight bash %} [jlengrand@ubuntu:~/downloads/OpenCV-2.3.1/release]$sudo apt-get install libgtk2.0-0 libgtk2.0-dev {% endhighlight %}
But during the compilation, you might encounter the following error :

{% highlight bash %}

...

/home/jlengrand/downloads/OpenCV-2.3.1/modules/highgui/src/cap_libv4l.cpp:1673: error: ‘struct CvCaptureCAM_V4L’ has no member named ‘memoryBuffer’
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_libv4l.o] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
{% endhighlight %}

This error is due to libv4l, which causes problems to openCV. Here is a simple way to get rid of the error :

  • Remove libv4l for your system.
WARNING : Do not reboot before the end of the operations, or your display will fail to start!
{% highlight bash %} [jlengrand@ubuntu:~/downloads/OpenCV-2.3.1/release]$ sudo apt-get remove libv4l-dev libv4l-0 The following packages will be REMOVED: gstreamer0.10-plugins-good libgstfarsight0.10-0 libpurple-bin libpurple0 libv4l-0 libv4l-dev pidgin vlc vlc-nox vlc-plugin-notify vlc-plugin-pulse 0 upgraded, 0 newly installed, 11 to remove and 37 not upgraded. After this operation, 28.1 MB disk space will be freed.Do you want to continue [Y/n]? Y {% endhighlight %}
Keep trace of all packages noted for removal, to reinstall them in last step.
  • Then finish OpenCV compilation:
{% highlight bash %} [jlengrand@ubuntu:~/downloads/OpenCV-2.3.1/release]$ make ... [jlengrand@ubuntu:~/downloads/OpenCV-2.3.1/release]$ sudo make install {% endhighlight %}
It should compile without error.
  • Finally, you simply have to reinstall all previously removed packages (which depends on your system).

{% highlight bash %}
[jlengrand@ubuntu:~/downloads/OpenCV-2.3.1/release]$sudo apt-get install gstreamer0.10-plugins-good libgstfarsight0.10-0 libpurple-bin libpurple0 libv4l-0 libv4l-dev pidgin vlc vlc-nox vlc-plugin-notify vlc-plugin-pulse
{% endhighlight %}

There it is, the library is successfully installed, you may use it as you wish ;).