0

OpenCv Book and basics

Posted by SUYOG PATIL on 11:03 PM in , , ,
Hello guys,
After long time i am writing this tutorial on OpenCV.
Now you must have some basic idea about OpenCV and how to setup it in different IDEs from my last posts.If you have any query then feel free to ask by mailing me or commenting directly below the post.Comments are preferred as they will help others too in debugging.

Let us start with the book which should be read to get an brief knowledge about OpenCV structure and programming methods.I want to suggest you only one book which i read during early days of my learning OpenCV and that is "Learning OpenCV by O'Reilly".The book is available on net for opensource community.

It is truly an awesome book to start and you must read it....
Most of my examples and code samples will be based on them..

You can read blogs also to get tutorials and code samples directly for small applications.
useful links:
Introduction To Computer Vision Using OpenCV
Introduction to OpenCV
openCV
FullOpenCVWiki
Introduction OpenCV

If you go through these sites thoroughly then you will become master in Opencv in few days!!!

So lets start with OpenCV naming conventions.
  • Function naming conventions:
        cvActionTargetMod(...)
        Action = the core functionality (e.g. set, create)
        Target = the target image area (e.g. contour, polygon)
         Mod    = optional modifiers (e.g. argument type)
      
  • Matrix data types:
        CV_<bit_depth>(S|U|F)C<number_of_channels>
    
        S = Signed integer
        U = Unsigned integer
        F = Float 
    
        E.g.: CV_8UC1 means an 8-bit unsigned single-channel matrix, 
              CV_32FC2 means a 32-bit float matrix with two channels.
     
  • Image data types:
        IPL_DEPTH_<bit_depth>(S|U|F)
    
        E.g.: IPL_DEPTH_8U means an  8-bit unsigned image.
              IPL_DEPTH_32F means a 32-bit float image.
     
  • Header files:
        #include <cv.h>
        #include <cvaux.h>
        #include <highgui.h>  
 These conventions may look confusing at the beginning but as we proceed you will get more familiar to them.

Basic OpenCV data structures

Image data structure


  • IPL image:
    IplImage
    |-- int  nChannels;     // Number of color channels (1,2,3,4)
    |-- int  depth;         // Pixel depth in bits: 
                           //   IPL_DEPTH_8U, IPL_DEPTH_8S, 
    |                       //   IPL_DEPTH_16U,IPL_DEPTH_16S, 
    |                       //   IPL_DEPTH_32S,IPL_DEPTH_32F, 
    |                       //   IPL_DEPTH_64F
    |-- int  width;         // image width in pixels
    |-- int  height;        // image height in pixels
    |-- char* imageData;    // pointer to aligned image data
    |                       // Note that color images are stored
    in BGR order
    |-- int  dataOrder;     // 0 - interleaved color channels, 
    |                       // 1 - separate color channels
    |                       // cvCreateImage can only create 
                               interleaved images
    |-- int  origin;        // 0 - top-left origin,
    |                       // 1 - bottom-left origin 
                               (Windows bitmaps style)
     
    |-- int  widthStep;     // size of aligned image row in bytes
    |-- int  imageSize;     // image data size in 
                              bytes = height*widthStep
    |-- struct _IplROI *roi;// image ROI. when not NULL specifies 
    |                       // image region  to be processed.
    |-- char *imageDataOrigin; // pointer to the unaligned origin 
                                 of image data
    |                   // (needed for correct image deallocation)
    |
    |-- int  align; // Alignment of image rows: 4 or 8 byte alignment
    |              // OpenCV ignores this and uses widthStep instead
    |-- char colorModel[4]; // Color model - ignored by OpenCV
    




 

Matrices and vectors 



  • Matrices:
    CvMat                      // 2D array
      |-- int   type;          // elements type (uchar,short,int,float,double)
                                and flags
      |-- int   step;          // full row length in bytes
      |-- int   rows, cols;    // dimensions
      |-- int   height, width; // alternative dimensions reference
      |-- union data;
          |-- uchar*  ptr;     // data pointer for an unsigned char matrix
          |-- short*  s;       // data pointer for a short matrix
          |-- int*    i;       // data pointer for an integer matrix
          |-- float*  fl;      // data pointer for a float matrix
          |-- double* db;      // data pointer for a double matrix
    
    
    CvMatND               // N-dimensional array
      |-- int   type;     // elements type(uchar,short,int,float,double) 
                             and flags
      |-- int   dims;     // number of array dimensions
      |-- union data;
      |   |-- uchar*  ptr;// data pointer for an unsigned char matrix
      |   |-- short*  s;  // data pointer for a short matrix
      |   |-- int*    i;  // data pointer for an integer matrix
      |   |-- float*  fl; // data pointer for a float matrix
      |   |-- double* db; // data pointer for a double matrix
      |
      |-- struct dim[]; // information for each dimension
          |-- size; // number of elements in a given dimension
          |-- step; // distance between elements in a given dimension
    
    
    CvSparseMat // SPARSE N-dimensional array
    
  • Generic arrays:
    CvArr* 
    // Used only as a function parameter to specify that the
    // function accepts arrays of more than a single type, such
    // as: IplImage*, CvMat* or even CvSeq*. The particular array 
    // type is determined at runtime by analyzing the first 4
    // bytes of the header of the actual array.
    

  • Scalars:
    CvScalar
      |-- double val[4]; //4D vector
    
    Initializer function:
    CvScalar s = cvScalar(double val0, double val1=0, double val2=0, double val3=0);
    
    Example:
    CvScalar s = cvScalar(20.0);
    s.val[0]=10.0;
    
  • Points:
    CvPoint      p = cvPoint(int x, int y);
    CvPoint2D32f p = cvPoint2D32f(float x, float y);
    CvPoint3D32f p = cvPoint3D32f(float x, float y, float z);
    
    E.g.:
    p.x=5.0;
    p.y=5.0;
    
  • Rectangular dimensions:
    CvSize       r = cvSize(int width, int height);
    CvSize2D32f  r = cvSize2D32f(float width, float height);
    
  • Rectangular dimensions with offset:
    CvRect       r = cvRect(int x, int y, int width, int height);
    




Ohh quite big...hence I am stopping here. Next time we will see some 
code examples so that you understand it better.Till then keep 
referring those sites which I have given for their good information 
content.My tutorials are based on those links and Oreilly book.
So keep in touch.

 
Have a great programming summer!!!




Links to this post |

Copyright © 2009 ALL ABOUT ROBOTICS!! All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.