February 1, 2014

OpenCV installation in ubuntu

Click here to read about installation in windows

This tutorial is meant for the Linux users who wants too configure OpenCV in Codeblocks platform. I assume that you have already installed codeblocks from the Software Centre or by extracting and making using the Makefile. You can download Code Blocks from the following link.

Download OpenCV

After properly setting up Visual Studio in your computer, The next step is to download OpenCV from the sourceforge site. Its always recommended to download the latest stable release. The beta versions may be under development and so you may download those versions only under your risk.
Now follow the link given below to download openCV for Windows.Download OpenCV

Extract OpenCV

After having downloaded the tarball file(tar.gz file), untar it. I am making an assumption that the OpenCV tarball name is opencv-2.4.6.tar.gz, and that my tarball is in the Desktop.In order to untar the file open terminal and navigate to the Desktop and use the tar command

cd ~/Desktop
tar -zxvf opencv-2.4.6.tar.gz
cd Opencv-2.4.6
The extraction will take quite a while to complete. Once completed, you may go to the installation directory and make sure that it looks something like this. For that type ls in the terminal. You must see something like this.

Before making opencv, we have to ensure that all the necessary libraries and softwares have been installed. For that run the following command in the terminal.

sudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg zlib1g zlib1g-dev libjasper-dev libjasper-runtime libjasper1 pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev python-numpy

remove any library or software which is creating problem in the above step.Now recheck whether you are in the Opencv-2.4.6 folder.Now we have to create a folder named “release”.

mkdir release
cd release

Now build the OpenCV using the following command.


Now make and install OpenCV using the following commands.

sudo make install

This step will take quite a long time to complete. Its better to ensure that you keep your laptop plugged while making OpenCV.
Now we have to add the library path of OpenCV to linux. Inorder to do that follow these commands:

cd /etc/ld.so.conf.d
touch opencv.conf
sudo gedit opencv.conf
Add the following line to the file, save and close it.


Now run the following command to complete the installation.

sudo ldconfig -v
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

Inorder to check whether the opencv has been properly installed, you can type in the following in the terminal:

pkg-config opencv --libs
pkg-config opencv --cflags
You must get an output looking sompething like this:



Configure Code Blocks

Once you have ensured that the OpenCV has been properly installed in your system, the next step is to integrate it into an IDE. In this tutorial I am using Code Blocks but it also works for any other IDE. I prefer IDE because the auto complete option makes coding simplified.
Now open CodeBlocks. I am using CodeBlocks 12.11.
Now go to settings –>compiler
Under the compiler settings tab select the other options tab and copy the following command into the pane.Make sure that you are not using the apostrophe but the symbol just next to the number 1 on your keyboard.

`pkg-config opencv –cflags`

Now open the Linker Settings Tab and copy the following command int the other linker options pane:

`pkg-config opencv –libs`

Now open the search directories tab and add the following locations :


Click OK to save the settings.
The last step is to enable autocomplete feature of CodeBlocks. Auto complete is a helpful feature of Code Blocks, as we dont have to remember the numerous functions and its parameters when coding in OpenCV.

Now Inorder to enable auto complete open the editor options from the settings menu. and make the selections as shown below:

Test your installation

Now Inorder to test whether the installation was proper, you may copy the following code to your project either in Visual Studio in the case of windows or CodeBlocks in the case of Linux. Build and run the code.

1 thought on “OpenCV installation in ubuntu

  • Hey there! Would you mind if I share your
    blog with my zynga group? There’s a lot of folks that I think would really appreciate your content.
    Please let me know. Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *