Friday, April 5, 2013

Installing OpenCV 2.4.4 on Ubuntu

Summary of Steps
References  and resources
1. For installation steps (for step 1 and 2)= http://opencv.willowgarage.com/wiki/InstallGuide#Prerequisites
2. For compilation steps (for step 3)= http://opencv.willowgarage.com/wiki/CompileOpenCVUsingLinux
3. For compilation steps (for step 4)= http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage
4. http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/

STEP 1: install the packages
$ sudo apt-get install cmake (if the system is fresh - do a sudo apt-get update)
$ sudo apt-get install pkg-config (if not already installed)
$ sudo apt-get install libgtk2.0-dev
sudo apt-get install libavformat-dev libswscale-dev 

STEP 2:
download the opencv-2.4.4a (base link for all the versions is http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/ - at the time of this writing 2.4.5 got released a few hours ago)

Exctract the tar archive this way
$ tar --bzip2 -xvf OpenCV-2.4.4a.tar.bz2
# a folder opencv-2.4.4 is created
$ cd opencv-2.4.4
$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..

# in my case at this stage the cmake reported no problems - when it does then check if the required packages listed in step 1 are properly installed.

$ sudo make install

STEP 3:

Now set an environment variable in the file /etc/environment
$ sudo echo 'PKG_CONFIG_PATH=/path/to/the/release/folder:$PKG_CONFIG_PATH' >> /etc/environment
(if above statement does't work then go to the file and add the line given in single quotes (and don't put the quotes in the file))

#now logoff and login
#test the pkg-config


$ pkg-config --cflags opencv
-I/where/you/have/installed/opencv/include/opencv  
$ pkg-config --libs opencv
-L/where/you/have/installed/opencv/lib -lcxcore -lcv -lhighgui -lcvaux 
 
If the PKG_CONFIG_PATH is set properly then you output will be quite similar to the above two outputs. (your output may be different, but look for any usual lines reporting error or no output at all)
 
STEP 4:
simply follow the simple tutorial at http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage for your first program to run.

2 comments: