Wednesday, 11 May 2011

Introduction to OpenCV for Image Processing

OpenCV (Open Source Computer Vision) is a computer vision library available from []. It is an open source library written in C and C++ and runs under Windows, Linux and Mac OS X. OpenCV has lot of inbuilt functions that you can use for your image processing and computer vision needs. It is mainly aimed at real time applications.

In this article,I will be telling u how to install OpenCV on your computer and integrating with Code::Blocks IDE so that you can say ‘hello’ to the world of image processing.

The latest version of OpenCV can be downloaded from

Configuring Code::Blocks and integrating OpenCV
STEP1: From the main menu select: Settings -> Compiler and debugger
Set the Selected Compiler to GNU GCC Compiler

In the window select, Global compiler settings and go to the tab, Linker Settings 
Click Add and add all the following directories one by one


In the window select, Global compiler settings and go to the tab, Search directories -> Compiler
Click Add and add all the following directories one by one


Now go to the Linker tab (next to the Compiler tab) and add the following directory


STEP2: In the header file cxoperations.hpp ,edit it by adding   __MINGW32__  to the end of line number 68 or replace the line by the line given below.
    #if __GNUC__ >= 4 || __MINGW32__

Now, you have completed the installation of OpenCV and are good to go.

Lets start with a basic program like reading an image and displaying it.

//Headers to include opencv library
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main()

IplImage* img = cvLoadImage("E:/walls/014.jpg");    //load an image. Note the "/" is used.

cvNamedWindow("Image", CV_WINDOW_AUTOSIZE);  //Create window to display image

cvShowImage("Image", img);       //View image

cvWaitKey(0);                           //Program waits till eternity for a key to be pressed.

cvDestroyWindow("Image");            //Destroy window

cvReleaseImage(&img);                   //Release image

return 0;


The image will be displayed till a key is pressed.
Congrats! u have just written ur 1st OpenCV program. :)

In case of any queries, contact me at my mail:-  or reply on the post.


  1. ye download to gayi par open nahi ho raha can u help.......and i am really interested in robotics.......and want to know much abt it

  2. I guess,u have downloaded only OpenCV.
    It is a library, and to use it, u need an IDE.
    So,to use it,u need Code::blocks, with which OpenCV will be integrated.
    Then follow the steps as above.

  3. You should write a Visual Studio integration article.. I'm playing around with it now, I'll let you know how it goes.

  4. libcxcore200.dll missing
    This is d error i am getting wen i executed this program.

    1. U could put the specific dll file from the OpenCV folder. in the directory where u are working...It will solve the problem

  5. There could be 2 reasons for this

    1. libcxcore200.dll file could be missing. Search for the file. If missing install Opencv again.

    2. U are using .c as file extension. Change the extension of file to .cpp

  6. The project name should be saved as "filename.cpp"

  7. sir, i get a grey box instead of the indicated .jpg file.actually img is a null pointer after cvLoadImage() is called. plz help me out

  8. I guess u have given the path of file in a wrong way..
    Instead of "\", use "/".
    See the slash is reverse.

  9. Hi, I'm lost in step two, where do I find cxoperations.hpp?

    1. It is in the include folder

  10. in opencv\include\opencv\ I am getting these files...

  11. You have given C:\OpenCV2.0\lib\libcv200.dll.a etc files to be added. I don't have a directory that goes like C:\Opencv\lib\...\. I only have 'lib' in C:\opencv\build\x64\mingw\lib\ and C:\opencv\build\x64\vc11\lib\. Of these two, the former link has dll.a type of files though the filenames are not exactly the same as ones you have given above whereas the latter has .sdb files with both debug and non-debug versions. Which library should I include ?

    Secondly, I dont have a cxoperations.hpp at include\opencv.

    I am using opencv 2.4.5 and a 64 bit OS (Win 7).

  12. Hello!
    Pynten, and others, to solve problems using the old version of OpenCV (same of the author), the 2.0 version.
    And to address image using "\ \" or "/".

    Thanks for tutorial!

  13. what IDE did you use base on the illustration above on step 1? im using VS2010. where is this settings you referring to?

  14. i have used .cpp extension and libcv200.dll is also present still devcpp is showing that libcv200.dll is not present..pls help sir..

  15. Amit .. I am struggling to create haar cascade xml file and gone through many articles. I have done yours too. But still am facing problem. Can you please share me your contact number? So that, I will contact u for 2 minutes. Or else. can u send me a sms to 7667662422. So that, I will call u.

    Microsoft MVP