Showing posts with label OpenCV. Show all posts
Showing posts with label OpenCV. Show all posts

Overview of EmguCV

One of my projects required me to work with OpenCV libraries in Windows platform. OpenCV as you all know is in C language. I wanted to give a nice interface to my project. Since the codes were in C, i initially thought of implementing it using Visual C++.

3 reasons that made me drop VC++
  • The setup to make OpenCV work with VC++ was not that simple.
  • The quality of interface developed is not very good.
  • C# and some of the other .NET compatible languages are more stable than C. I came to this conclusion because for me the code in C used to crash more than in C#.

I found C# language provided better and simpler interface development tools. Thats when i started looking for .NET wrapper for OpenCV. There are lots of open-source .NET wrappers available. Here's a clear comparison between them. Out of them i found EmguCV is the better one and decided to use it.

Emgu CV is a cross platform .Net wrapper. Allowing OpenCV functions to be called from .NET compatible languages such as C#, VB etc. The wrapper can be compiled in Mono and run on Linux / Mac OS X.
Category: , 1 comments

Use of Hough circles in OpenCV

OpenCV provides and inbuilt function to detect circles in your image. The Hough transform is a technique which can be used to isolate features of a particular shape within an image. The implementation of the circle  transform in OpenCV uses a tricky method called the Hough gradient method ( Link to Google Books ).


cvHoughCircles( ) is the function provided in OpenCV.

CvSeq* cvHoughCircles( 
        CvArr* image,         
        void*  circle_storage, 
        int    method, 
        double dp, 
        double min_dist, 
        double param1 = 100, 
        double param2 = 300, 
        int    min_radius = 0, 
        int    max_radius = 0 
      ); 

Following is a example code snippet.

How to setup OpenCV 2.2 in Codeblocks


The thing with OpenCV libraries is that the method to set it up with codeblocks is different for every newer version! The last tutorial I posted was for Setting up OpenCV 2.0 with codeblocks. In this post I would follow the similar method and try  to be as clear as possible.
I will be using codeblocks 10.05 and OpenCV 2.2 on Windows 7 operating system. MinGW compiler ( The GNU GCC compiler ) in the codeblocks. So first check if your code blocks has this compiler installed. If no, then download one from the link below.



Download the latest version of codeblocks and OpenCV from the below links.
Code Blocks                  OpenCV 2.2

Follow the normal installation for code blocks. I couple of things to note during OpenCV installation is that it should be installed in the C:\ and  the environment variable PATH should be set. You would be prompted during the installation.

How to convert IplImage to a matrix in OpenCV


Getting a digital image into numbers can be very handy for your image processing. In this post i will brief just that. I am a beginner in OpenCV and i found it very difficult to find material to do this. I was looking for storing a 8-bit image, 3 channel image into a 3D matrix. That's the method i am going to explain in this post.

Before i get on with the implementation, i would like to brief about the matrix structure that we are going to use. Its a 3D matrix; the row and column values represent the respective X and Y co-ordinates of the image. That is each value in the matrix represent a pixel. I am considering a 3 channeled image, so each pixel will have 3 channel values i.e for BGR. For more info on the matrix basic you can refer this link.

Following is the method I used..

First load a 8-Bit image with 3 channels RGB and create define a matrix structure accordingly.

          IplImage *img = cvLoadImage( "cataract.jpg");
    CvMat *mat = cvCreateMat(img->height,img->width,CV_32FC3 );

Next use the cvConvert function. cvConvert is a Macro provided by OpenCV which is the same as cvConvertScale() but is conventionally used when the scale and shift arguments will be let at their default values. 

           cvConvert( img, mat );

That does the work! Now your IplImage is stored into the matrix. You can retrieve the matrix values just by specifying the corresponding X,Y co-ordinate values in the cvGet2D function. I have used a for loop to print the RGB values of a small portion of the image.


        for(int i=0;i<10;i++)
        {
          for(int j=0;j<10;j++)
            {
               CvScalar scal = cvGet2D( mat,j,i);
               printf( "(%.f,%.f,%.f)  ",scal.val[0], scal.val[1], scal.val[2] );
            }
          printf("\n");
        }

cvScalar function is used to define a variable that stores the RBG value retrieved. You can check the OpenCV Reference links for some more tutorial links on OpenCV.

Please leave a comment so that know if this post is helpful or not. Also mention if any changes is required. It could help others :)



OpenCV Tutorial References


OpenCV is a well defined set of library function used in the field of Computer Vision.

It is a computer vision library originally developed by Intel but now supported by Willow Garage.The library is open source, cross platform mainly focusing on real time image processing.

Example applications of the OpenCV library are Human-Computer Interaction (HCI); Object Identification, Segmentation and Recognition; Face Recognition; Gesture Recognition; Motion Tracking, Ego Motion, Motion Understanding; Structure From Motion (SFM); Stereo and Multi-Camera Calibration and Depth Computation; Mobile Robotics. 

OpenCV library provides very well advanced functions for image storage, manipulation and object identification making things simpler. Eg: Just 2 simple functions cvHaarDetectObjects () and cvGetSeqElem () are sufficient to perform face detection!

I have went through many web links for my initial preparations on OpenCV. There are many tutorials out there, but i manage to pick a few of the better ones and thought of posting them here. I would brief on the web links so that you can choose your tutorial accordingly.

Web Links
  1.  Tutorial by Noah Kuntz
    • I found this OpenCV tutorial best for a beginner. He has touched upon all the details along with sample programs. 
    • He has categorized the tutorial into 11 segments and each segment is explained very well.
    • In case you are not through with C programming language there is a tutorial for that also.
    • Click here for the tutorial
     2.   Tutorial on Sourceforge.net
    • This tutorial makes use of Flowdesigner plug in along with OpenCV. You can download the plugin from here as its open source.
    • Tutorial provides a detailed explanation for all the basic library functions.
    • Best part is that the library functions are explained along with Image samples. That can really help in better understanding of the concept. 
    • Click here for the tutorial

How to setup CodeBlocks for OpenCV programs



In this tutorial i will be using OpenCV v2.0 and Code Blocks v10.05 with GNU compiler on Windows 7 operating system. Using OpenCV v2.2? Then you can check this post "Setup OpenCV 2.2 in codeblocks"


To work on OpenCV with Code Blocks you just need to add some libraries. Following are some simple steps that I followed.

  1. First of all i assume you have downloaded the OpenCV package and installed in your system. ( Not exactly install, just extract ) If not you can Download it from here. 
  2. Make sure the environment variable PATH is set. This could be done during the installation procedure itself. It will prompt you with this question. If you missed that then you have to manually add it. 
  3. Considering you have the OpenCV installed in your C drive, I continue with the method.
  4. Open Code Blocks.
  5. Goto menu Settings > Compiler and Debugger > Search Directories
  6.  There goto Add and add the directory C:\OpenCV2.0\include\opencv