OpenCV on Linux again with G++

UPDATE: I’ve update this entry for the latest OpenCV (2.3.1).   For more information I recommend to look for the related information from this site:
And the installation details are on this site:
I believe this website should contains all the related references and tutorials for your OpenCV project. Best Wish.

After a long way try to develop C program with OpenCV library on Ubuntu Linux using NetBeans and Eclispe IDE, no succeed at all. There are always some problems occurs and the project cannot move on further so everything has to be move back onto Windows to be developed. But now all these thing can be developed in Linux by  using traditional GNU C Compiler (GCC) that most of Linux users know it very well. This is the complete procedure from the beginning(install) till the end(compile-build).

Part A. Install OpenCV 2.3.1

1. Install prerequisites

Enter this line into Linux Terminal:

$sudo apt-get install build-essential cmake libgtk-3-dev pkg-config ffmpeg libjpeg-dev libpng-dev libtiff-dev libavformat-dev libswscale-dev bzip2;

All these packages are the prerequisites for compiling and running OpenCV.

2.Get OpenCV 2.3.1 sourcecode

Obtains the sourcecode of OpenCV by visit Sourceforge and download OpenCV2.3.1a.tar.bz2 (Unix tarball)

3. Extract and Compile OpenCV 2.3.1

3.1 Extract by enter
$tar xvjf OpenCV-2.3.1a.tar.bz2
3.2 Enter the directory
$ cd OpenCV-2.3.1/
3.3 Create a output directory
$mkdir release; cd release
3.4 COMPILE The OpenCV
This is the important one! For more information please see in Ref1 below.
3.5 Install OpenCV
$sudo make install

In some case if you cannot compile OpenCV successfully, possibly your ffmpeg might be out-dated. Try install the latest one using instruction here:

* I also found that there is an issue between the latest ffmpeg (0.10) with opencv. At this time, I recommend to use the older version of ffmpeg instead.
3.6 Exporting Part
$export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
$sudo ldconfig

Part B Compile application with GCC using G++

This part is amazingly easy as eating an ice-cream!
All we have to do is to get into your project directory in Terminal, then use this command to compile your program!

$g++ -o ProgramName ProgramName.c `pkg-config opencv --cflags --libs`

That’s it! And we can execute our program by using command:

That’s all we need to do to use OpenCV 2.0.0 on Linux system.

Part C Program Example
Example code of OpenCV application can be found on Ref1. below.

This is the screenshot of my running program.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s