Friday, July 6, 2012

Building OpenCv 2.4.2 on Ubuntu 12.04

In Ubuntu 12.04 only OpenCv 2.3 is available. To exploit the examples in Abid Rahman's blog, at least OpenCv 2.4 is necessary.
To install OpenCV 2.4.2, open you package manager (synaptics) and uninstall if necessary previous OpenCv version. Check if the required/optionnal libraries are installed, for example:
                          
                          Commit Log for Wed Jul  4 21:38:54 2012

                          Les paquets suivants ont été installés :
                          libtbb-dev (4.0+r233-1)
                          libtbb-doc (4.0+r233-1)
                          libtbb2 (4.0+r233-1)
                          tbb-examples (4.0+r233-1)

cmake must be installed, it's convenient to install cmake-gui too. Download OpenCv 2.4.x (here 2.4.2) and uncompress the archive in some directory. Make an other directory to build OpenCV:

For example, in a directory called Applications,  the OpenCv source code is in OpenCv-2.4.2 and an empty directory Build OpenCv242.
Run cmake-gui, it can be found from the dash:

looking for CMake with the Dash

Once cmake run, select the directory containing OpenCv source code, and the target directory that will contain the build OpenCv:

CMake gui running after having selected the source code directory and the build directory
Within cmake, check the different options that are needed (tiff support, python ...), click on the configure button, then on generate. If everything went fine, open the destination directory, open a console in it and type the commands:

                                                        make
then 
                                                         sudo make install

The options selected can be found in the CMakeCache.txt file.

The installation can be checked by opening a ipython shell and importing cv2 as follow:
ipython shell after cv2 importation
The auto completion can find some function implemented in OpenCv (cv2).

5 comments:

abid rahman k said...

Hi,

Can you have a detailed explanation with screen shots on how to build latest OpenCV on Ubuntu?

dip4fish said...

Hi,
I have modified some explanations and added legends to the screen shots.

abidk said...

Hi,

Can you have a detailed list or screenshot of cmake-gui showing which are all fields to be checked in a minimal condition? I think some of the fields, we have to specify some paths ( i am not sure ). I am stuck at that stage. So it would be great if you add that also.

dip4fish said...

Sorry for delay. I'll try to do that.

dip4fish said...

I modified the text to include a link to the cmake cache file which gives the options selected in cmakegui to build opencv.