Am I not cultured enough to learn OpenCV?

June 12, 2010

My recent visit to Chennai’s City Centre Mall changed my daily routine. I have a very bad habit of buying books whenever I stroll in to a bookstore to have a look. I visited the ubiquitous Landmark and my eyes struck a copy of “Learning OpenCV” by Gary Bradski and Adrian Kaehler.

I was educated about OpenCV quite a long time back but I never got an opportunity to get my hands on it. I bought this copy to realize my wishes. I have been struggling to write my “Hello World example” using the OpenCV libraries.

I hope you had read my earlier post on building the OpenCV library. I am a beginner in C++ programming and I felt it quite difficult to understand the arguments and commands used with the OpenCV library.

However, this tutorial by Gavin Page came to the rescue:


My new image read “Hello world!” Yupeee.

When I compiled my first code from the book, I was happy enough to press the “Start Debugging”

Now this was the error that I received 😦

I couldn’t understand what was going on.  The author has made a special mention that:

A proper program would check for the existence of argv[1] and, in its absence, deliver an instructional error message for the user. We will abbreviate such necessities in this book and assume that the reader is cultured enough to understand the importance of error handling code.

I was shocked to read this. Since I had a friend who is an expert in programming, he told me that that I am using a command line argument function

He told me that I either had to use a file pointer or a command prompt to execute the code correctly.

So I searched the web for this information and found that my friend was right. I had to go to the directory where my compiled exe file is located and pass the image file as an argument to the exe file.

This is how you are supposed to do it

>opencv.exe F:\affidavit.jpg

Bingo! I was able to load my image. Now, I wanted to load a video using the example from the book. I wasn’t cultured enough to understand the problem behind the code once again. The code execution was perfect but no video was loaded!

Google came to the rescue. This is what OpenCV wiki had to say.

You have to use tools like mencoder to convert the avi files into compatible formats.

This is the command I used for the mencoder.exe file

>mencoder.exe in.avi -ovc raw -vf format=i420 -o out.avi

Please note that the converted video is of a bigger file size.

After conversion, you may execute the converted file as follows:

>opencv.exe out.avi

I am worried about the n number of surprises that I would come across in the days to come 😦

Open CV

June 7, 2010

I completed my first project in OpenCV after an eight hour struggle.

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision.

You may download the latest version @ Source Forge

I bought the official tutorial for OpenCV which is a very good book.

You will need CMake and MinGW as a pre-requisite.

After you have finished installing OpenCV( don’t forget to include the path while installing. Else, you have to do it manually)

You have to compile the Open CV files before you launch your project.

You may use the CMake GUI to compile your files.

You have to specify the source directory as the OpenCV directory and the destination may be any preferred temporary directory.

Click on Configure followed by Generate in your CMake GUI.

Once the output tab displays “Generating done”, your ready to launch your first project.

To be continued….

Histogram equalisation using Matlab

August 24, 2009

I have started learning the Image Processing toolbox of Matlab. My second tutorial was Histogram equalisation.

I downloaded a rice grain image shown  below: Rice grain image before equalisationNow, the following code was used:

I = imread(‘rice.png’)  // The image is in the working directory.


The histogram of the image is shown in the figure below:

Histogram of ImageThe image was equalised using the following commands:

I2 = histeq(I);

figure, imhist(I2)

The equalised histogram is shown below:

Histogram EqualisationAn image with an improved contrast was obtained as shown in the image below:

aftereqBingo! The contrast of the image has improved!!!

Matlab Image Acquisition

August 22, 2009

Thanks to Madan!

I learnt Image acquisition using Matlab Image Processing toolbox.

Now I can acquire videos using Matlab tool. My goal is to learn identification of colours from the acquired videos.  For more details, please refer to Mr.Madan’s tutorial on image acquisition.

I have a Logitech Quick Cam Camera installed to my system.  Also, I have Matlab 7.5 installed in its place. To check whether your Matlab tool box has an Image Processing Tool Box, Here is what you have to do:

Bingo! Your Matlab software has the Image Processing Tool Box

Bingo! Your Matlab software has the Image Processing Tool Box

Now type : ‘ imaqhwinfo ‘ in the command window to find the installed video drivers in your PC.

Here is something which you may read:

>> imaqhwinfo
ans =
InstalledAdaptors: {‘coreco’  ‘winvideo’}
MATLABVersion: ‘7.5 (R2007b)’
ToolboxName: ‘Image Acquisition Toolbox’
ToolboxVersion: ‘3.0 (R2007b)’

>> imaqhwinfo

ans =

InstalledAdaptors: {‘coreco’  ‘winvideo’}

MATLABVersion: ‘7.5 (R2007b)’

ToolboxName: ‘Image Acquisition Toolbox’

ToolboxVersion: ‘3.0 (R2007b)’

Now I connect my web cam to the PC and here is what I do to read an image:

1)  Type the adaptor name and resolution of the video.

vid = videoinput(‘winvideo’,1,’RGB24_320x240′);

2) Preview the video using your matlab tool and enjoy by typing the following command


Acquired video

More image processing tutorials to follow!