September 27, 2011

Install OpenCV on Linux (Ubuntu)


Unlike OpenCV in windows, you don't need visual studio to execute your OpenCV programs in Linux.

Following are the steps to install OpenCV on Linux-Ubuntu. Copy and execute following code lines in Ubuntu terminal one by one. Remember, you need internet connection for this installation.

1. You require a g++ compiler for programming.
$ sudo apt-get install g++

2. OpenCV requires GTK+ 2.0 or higher version to display images.To install GTK+,
$ sudo apt-get install libgtk2.0-dev

3. Go to Synaptic Package Manager (System> Administration> Synaptic Package Manager)

4. Search for “opencv” and install the main “opencv” package and the following lib files:
libcv
libcv-dev
libcvaux
libcvaux-dev
libhighgui
libhighgui-dev
opencv-doc
(‘python-opencv’ not required).
(you can also install opencv directly from the terminal by “sudo apt-get install” the above lib files

5. After installing all the packages, open a terminal & type this code:
export LD_LIBRARY_PATH=/home/opencv/lib
export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig

The above ones are default paths for the opencv libraries.

6. To check the path where opencv & other lib files are stored, do:

$ pkg-config --cflags opencv
(output will come as)
-I/usr/include/opencv
$ pkg-config --libs opencv
(output will come as)
-lcxcore -lcv -lhighgui -lcvaux -lml

These paths are needed to compile your opencv programs.
In the next post, I will show you how to compile OpenCV programs in Ubuntu.

No comments: