Showing posts with label OpenCV. Show all posts
Showing posts with label OpenCV. Show all posts

Wednesday, May 16, 2012

OpenCV 2.4 on Ubuntu 12.04

Edit (August 2013): Just used these steps to install OpenCV 2.4.6.1 on Ubuntu 12.10 without problems.

OpenCV 2.4.0 was released on May 2012 providing, a lot of improvements and bug fixes. For a complete change log see here.

This post will hopefully make your life easier to configure, compile, install and test it out.

This time I tried to categorize and explain the dependencies, so that it is easier to configure it for your needs. As always, comments and suggestions are welcome.

Ubuntu 12.04 provides a package of OpenCV 2.3.1 that you can easily install by typing:
sudo apt-get install libopencv-dev
If you do not care about having the latest version you could skip the rest of the post.

Install Dependencies


Essentials
These are libraries and tools required by OpenCV.
sudo apt-get install build-essential checkinstall cmake pkg-config yasm

Image I/O
Libraries for reading and writing various image types. If you do not install then the versions supplied by OpenCV will be used.
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev


Video I/O
You need some or all of these packages to add video capturing/encoding/decoding capabilities to the highgui module.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev

Python
Packages needed to build the Python wrappers.
sudo apt-get install python-dev python-numpy

Other third-party libraries
Install Intel TBB to enable parallel code in OpenCV.
sudo apt-get install libtbb-dev

GUI
The default back-end for highgui in Linux is GTK. You can optionally install QT instead of GTK and later enable it in the configuration (see next section). 
sudo apt-get install libqt4-dev libgtk2.0-dev

Compile and Install

Get a copy of the source code here, extract and create a build directory:
tar -xvf OpenCV-2.4.0.tar.bz2
cd OpenCV-2.4.0/
mkdir build
cd build
Configure using CMake. You have a lot of options in this step. This is what I use:
cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
Notice, that by adding the -D WITH_QT=ON, the highgui module will use QT instead of GTK. If you want to go with GTK just remove this. For more information on the options, look at the CMakeLists.txt file. When you are happy with the configuration you have, you can start compiling:
make
If compilation finishes without errors, you can install by saying:
sudo make install
Finally, make sure that your programs can link to the OpenCV library in run-time by adding the following line at the end of your /etc/ld.so.conf:
/usr/local/lib
And then configure dynamic linker run-time bindings:
sudo ldconfig

Testing

An easy way to test that the compilation went well is to use the OpenCV test utilities. For example, to test the core module go to OpenCV-2.4.0/build/bin and run:
 ./opencv_test_core
You should see something like that:


Note that some failures when testing other modules may come from missing image files. To correctly run these tests or samples you should move the corresponding image files from OpenCV-2.4.0/samples to OpenCV-2.4.0/build/bin.

For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
make
This should compile and run with a test image, so you should see something like this:



Monday, September 26, 2011

OpenCV 2.3.1 on Ubuntu 10.10 or later

*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

This post will guide you on how to compile and run OpenCV 2.3.1 on Ubuntu 10.10 or later.

First, install all prerequisites:
sudo apt-get install build-essential checkinstall git cmake ffmpeg libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev libtbb-dev libv4l-dev libopenexr-dev libunicap2-dev libavformat-dev libswscale-dev libdc1394-22-dev libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg python-numpy
This is not a minimal set of libraries, but it's a collection that will give you most of the functionality. For example, if you are sure that you will never need to use a firewire camera, you can ignore libdc1394-22-dev. But if you actually need to use this feature you will have to recompile OpenCV. Also, if you need CUDA support, follow the instructions in this post before continuing here.

Download OpenCV:
wget downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2
Extract and create a build directory:
tar -xvf OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1/
mkdir build
cd build
Now run cmake:
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
At this point check the output of cmake to make sure that all the features you are going to need are supported. If not you will have to install the corresponding libraries and run cmake again. Compile:
make
If everything went well you can go ahead and install:
sudo make install
Finally, add the following lines in your .bashrc:
# OpenCV stuff
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
To test that everything works, let's run the face detection demo. Go to the bin directory:
cd bin
And run:
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="../../data/haarcascades/haarcascade_eye.xml" --scale=1.3 ../../samples/c/lena.jpg
You should see something like this:


Friday, February 25, 2011

OpenCV 2.2 on Ubuntu 10.10


*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. It is released under a BSD license, it is free for both academic and commercial use. It has C++, C, Python and soon Java interfaces running on Windows, Linux, Android and Mac.

This is how to build and install OpenCV 2.2 on Ubuntu 10.10.

First, install the dependencies from the repositories:
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
Download the source code:
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.2/OpenCV-2.2.0.tar.bz2
Extract, create the build directory:
tar xfv OpenCV-2.2.0.tar.bz2
rm OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0
mkdir opencv.build
cd opencv.build
Configure, make and install:
cmake ..
make
sudo make install
To configure the library, edit the following file (might be empty):
sudo gedit /etc/ld.so.conf.d/opencv.conf
and add the line
/usr/local/lib
Then run:
sudo ldconfig
Finally, edit the file:
sudo gedit /etc/bash.bashrc
and add the following lines at the end:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
Most of the above was find here.

Older versions? Take a look at the following links:

OpenCV 2.1 on Ubuntu 10.04 (pretty much the same as above, but with TBB)
OpenCV 2.0 on Ubuntu 9.10

For OpenCV 2.3.1 see this post.