Hello world !

wow finally hello world , you have been waiting for this right ;p. if you have setup all the things correct and added libraries to the IDE , then It’s time to do some nice simple coding.

fire up eclipse , now create a project and add libraries and library paths.

here is the code that I have used

* hello.cc
* Created on: Feb 23, 2013
* Author: ludkiller

//This file is for educational purpose


using namespace std;
using namespace cv;

int main(int argc, char **argv) {

Mat image;
//check if filename is provided through command line.
if(argc != 2)
return 0;
//imread function takes file name(if file exists in same directory as executable) or path to file
//and returns a Mat object.
image = imread( argv[1] );
//We can use if(!image.data) to check if image is loaded or not.
//namedWindow to create a window (highgui)
namedWindow(“Display Window”);
//imshow takes a window name and Mat object as parameters and shows a window.
imshow(“Display Window”,image);
//waitKey(x) waits till x ms . 0 is for infinity.
return 0;


ok now compile/build and run it using command line like this

./Hello_world image.jpg

this will open a nice image in a windows ;D, that’s what it does displays and image as you can see in below image.

Screenshot from 2013-02-23 22:02:34


now let us see what the code exactly does. I have commented the code so it will be easy if you just look at the code (you should know basics of C/C++)



the above files are included files which are needed for various function and classes.

like Mat class , namedWindow function and other functions.


using namespace std;
using namespace cv;

above namespaces are included to make program user friendly, if you don’t use these then you need to use scope resolution to resolve things present in other name spaces.

for example if you skip using namespace std;

std::cout<<“Hello world”;

and if you skip using namespace cv;

then you need to do cv::Mat to declare object of Mat class.

then comes our main() function the entry point of program.

 Mat image;

declare a object of Mat class.


return 0;

check if image path is provided or not if not then exit program.

image = imread(argv[1]);

argv[1] contains image path, so it’s passed on to imread(path to image);

namedWindow(“Display Window”);

create a window named “DIsplay Window”.

imshow(“Display Window”,image);

imshow is used to display image stored in a Mat Object.

first argument is window name and second object is object of class image with loaded image.


return 0;

waitKey(x) takes time as argument time is in milli second so waitKey(40); will wait for 40 ms.

Setting Up Eclipse CDT IDE

well now comes the most difficult part ;3, how to setup eclipse IDE CDT for C/C++ development

the process is really long, so tighten your horses.

Open terminal type

sudo apt-get install eclipse-cdt

guess what It’s done. 😀

yeah I know short and sweet ;p , now to run eclipse IDE open terminal type

eclipse &

ok Now we need to include Library paths for OpenCV in our includes :D.

follow the following images and you shall get your answer.

Start Eclipse > Create a New Project > Project > Properties.

Now follow these images.

add /usr/local/include/opencv to Include paths.

Screenshot from 2013-02-22 22:17:58

add /usr/local/lib to Library Search Paths as shown in image.

add following to Libraries as shown in image below


Screenshot from 2013-02-22 22:20:53

Getting Started (LINUX)

Now let’s set up OpenCV on our Ubuntu Machine.

You need following components to compile and install OpenCV libraries on your ubuntu system.

  • GCC 4.3 or later. In Ubuntu/Debian it can be installed with

 sudo apt-get install build-essential

  • CMake 2.6 or higher

sudo apt-get install cmake cmake-qt-gui

  • Subversion (SVN) client / Git

sudo apt-get install git

  • GTK+ 2.x or higher, including ers (e.g. libgtk2.0-dev)

sudo apt-get install libgtk2.0-0 libgtk2.0-dev

  • pkgconfig

sudo apt-get install pkg-config

  • libpng, zlib, libjpeg, libtiff, libjasper with development files (e.g. libjpeg-dev)

sudo apt-get install libpng12-0 libpng12-dev zlib1g zlib1g-dev libjpeg8 libjpeg8-dev libjpeg62 libjpeg62-dev libtiff4 libtiff4-dev libtiff5 libtiff5-dev libjasper1 libjasper-dev

  • Python 2.3 or later with developer packages (e.g. python-dev)

sudo apt-get install python2.7 python2.7-dev

  • SWIG 1.3.30

sudo apt-get install swig swig2.0

sudo apt-get install ffmpeg

  • libdc1394 2.x + headers for video capturing from IEEE1394 cameras

sudo apt-get install libdc1394-22 libdc1394-22-dev

Download OpenCV latest Stable version from their sourceforge repo


select the one you want 2.4.4 is the latest and stable one


extract the files from the archive anywhere you want, now cd into OpenCV-2.4.4 , do a mkdir release

now cd into release and type cmake-gui ../

a GUI will be presented click on configure , read and check the boxes you want , now click generate , ok so now we have geenrated some UNIX makefiles

cd into your OpenCV-2.4.4/release and then type sudo make install

now do a ldconfig -v

and then export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH  default installation directory is /usr/local/lib

FInally OpenCV is ready to be used 😀

Next tutorial will be about setting up Eclipse CDT IDE to make our life easy.

OpenCV : Starting of a dream

It was around winter when i first heard of the word OpenCV(Open Computer Vision), fascinating it was when i learned about stuff you can do with it, if you find it fascinating like I did, then you are at the right place, I am starting this blog to introduce newbies to the concept of OpenCV , how to process images , track things and other fun things. 😀

I will be working on Live projects so be sure to check my Git repo http://github.com/ludkiller

if you are interested we can work on Open Source projects.