• Save
RoboCV Module 3: Delving Deeper into OpenCV
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

RoboCV Module 3: Delving Deeper into OpenCV

on

  • 1,143 views

These are the slides of the RoboCV Workshop organized by roboVITics on August 11th-12th, 2012 in TT311 Smart Classroom, VIT University, Vellore. ...

These are the slides of the RoboCV Workshop organized by roboVITics on August 11th-12th, 2012 in TT311 Smart Classroom, VIT University, Vellore.

The workshop was delivered by the following people:
1. Mayank Prasad, President of roboVITics
2. Akash Kashyap, President of TEC - The Electronics Club of VIT
3. Akshat Wahi, Asst. Project Manager of roboVITics

Statistics

Views

Total Views
1,143
Views on SlideShare
892
Embed Views
251

Actions

Likes
1
Downloads
1
Comments
0

1 Embed 251

http://robovitics.wordpress.com 251

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

RoboCV Module 3: Delving Deeper into OpenCV Presentation Transcript

  • 1. ByMayank PrasadPresident, roboVITicsVIT University, Vellore DELVING DEEPER INTO OPENCV Data Types in OpenCV
  • 2. Outline2  OpenCV Primitive Data types  CvPoint,CvSize, CvRect, CvScalar  Constructors of data types  Matrix and Image Types  CvArr,CvMat, IplImage  CvMat Matrix Structure  IplImage Data structure  Matrix and Image Operators © roboVITics | Mayank Prasad, 2012
  • 3. 3 OpenCV Data Types Primitive Data Types Matrix and Image Types Inheritance Relationship © roboVITics | Mayank Prasad, 2012
  • 4. OpenCV Primitive Data types4  Several primitive data types in OpenCV  Not present in the traditional ANSI C  CvPoint – CvPoint2D32f, CvPoint3D32f  CvSize, CvSize2D32f, CvRect, CvScalar © roboVITics | Mayank Prasad, 2012
  • 5. OpenCV Primitive Data types5  Primitive Data types are normal C structures  Each data type has constructor method like cvSize(), cvPoint(), cvRect()  Since this is C, not C++, these “constructors” are inline functions which take in list of arguments and returns the desired data structure with values set properly.  CvScalar has three constructors: cvScalar(), cvRealScalar(), cvScalarA ll() © roboVITics | Mayank Prasad, 2012
  • 6. Matrix and Image Types6 © roboVITics | Mayank Prasad, 2012
  • 7. Inheritance Relationship7  Though OpenCV is programmed entirely in C, its structures implemented can be thought to exhibit object oriented design  IplImage is derived from CvMat, which is in turn derived from CvArr  Wherever CvArr* appears in function prototypes, it is acceptable to pass CvMat or IplImage to the routine © roboVITics | Mayank Prasad, 2012
  • 8. 8 CvMat Matrix Structure Matrix Header Creating, Initializing & Releasing Matrix Accessing Matrix Data © roboVITics | Mayank Prasad, 2012
  • 9. CvMat Matrix Structure9  Can be created from the following definition:  Type can be of the form:  For example  32bit floats CV_32FC1  Unsigned integer 8 bit triplets CV_8UC3  For multichannel images like RGB, operators act on each channel separately. © roboVITics | Mayank Prasad, 2012
  • 10. CvMat Structure: Matrix Header10  Matrices have  Width  Height  Type  Step (length of row in bytes)  Pointer to data array  And many more!!  All members can be accessed by de- referencing pointers or by calling accessory functions © roboVITics | Mayank Prasad, 2012
  • 11. Creating Matrices11  Can be created in three ways:  Create using cvCreateMat()  Create using cvCreateMatHeader() and cvCreateData()  Create from an existing one by cloning it cvCloneMat(CvMat*)  cvCreateMatHeader() creates CvMat structure without allocating any data  cvCreateData() handles data allocation  Release using cvReleaseMat(CvMat**) © roboVITics | Mayank Prasad, 2012
  • 12. Matrix Creation12 © roboVITics | Mayank Prasad, 2012
  • 13. Header Initialization13 © roboVITics | Mayank Prasad, 2012
  • 14. Header Initialization14 © roboVITics | Mayank Prasad, 2012
  • 15. Clone & Release Matrix15 © roboVITics | Mayank Prasad, 2012
  • 16. Create OpenCV Matrix16  Create an OpenCV Matrix with some fixed data float vals[] = {0.8660225, -0.5000000, 0.5000000, 0.4326678}; CvMat rotmat; cvInitMatHeader( &rotmat, 2, 2, CV_32FC1, vals );  Simple Matrix Operations  cvGetElemType() : Returns the type like CV_64FC4  cvGetDims() : Returns width & height  cvGetDimSize() : Returns the size © roboVITics | Mayank Prasad, 2012
  • 17. Accessing Matrix Data17  The easy way!  The hard way!!  The right way!!! © roboVITics | Mayank Prasad, 2012
  • 18. The Easy Way18  Use the CV_MAT_ELEM() macro  Takes in the matrix, type of element to be retrieved, row and column numbers  Returns the desired element  Under the hood, it calls CV_MAT_ELEM_PTR()  Type casting is required © roboVITics | Mayank Prasad, 2012
  • 19. Why not the easy way?19  Re-computes pointer needed on every call  Look up the pointer to the base element  Calculate the offset of the desired point  Add the offset to the base element pointer  Easy to use, but not the best way, especially when every element is to be accessed sequentially © roboVITics | Mayank Prasad, 2012
  • 20. The Hard Way20  Easy way deals with 1D and 2D matrices  Hard way can deal with N-dimensional matrices  Has a lot of set/get/pointer functions  It is a rarely used way, since many a times, vision is a processor-intensive activity, which requires greater efficiency  So, do your own pointer arithmetic and de- reference your way into the matrix  Important in cases when an OpenCV routine is not available for performing a particular task © roboVITics | Mayank Prasad, 2012
  • 21. The Right Way21  Direct access to innards of matrix  Data storedsequentially in raster scan order  Columns (“x”) are fastest running variable  Channels are interleaved © roboVITics | Mayank Prasad, 2012
  • 22. The Right Way22  Element data is Union  Step element can be used for offset  Since step element is in bytes, all pointer arithmetic is done in bytes, and later typecast into float  Pointer is recomputed for every row rather than starting from the beginning © roboVITics | Mayank Prasad, 2012
  • 23. Arrays of Points23  Not discussed © roboVITics | Mayank Prasad, 2012
  • 24. 24 IplImage Data Structure Header Structure Accessing Image Data ROI and widthStep © roboVITics | Mayank Prasad, 2012
  • 25. IplImage Data Structure25  Similar to CvMat, but with some extra goodies  Makes the matrix more interpretable as an image  This structure was originally defined as a part of Intel’s Image Processing Library (IPL)  It is defined as: © roboVITics | Mayank Prasad, 2012
  • 26. IplImage Header Structure26 © roboVITics | Mayank Prasad, 2012
  • 27. Depth & Channels27  width & height is ubiquitous  depth & nChannels are next most crucial  nChannels can be 1, 2, 3 or 4 © roboVITics | Mayank Prasad, 2012
  • 28. Origin & Data Order28  origin can take two values  Upper-left of the image, IPL_ORIGIN_TL  Lower-left of the image, IPL_ORIGIN_BL  dataOrder can be of two types  IPL_DATA_ORDER_PIXEL – data packed with multiple channels one after the other for each pixel i.e. interleaving  IPL_DATA_ORDER_PLANE – all the channels clustered into image planes with planes facing each other – not supported in OpenCV © roboVITics | Mayank Prasad, 2012
  • 29. Interleaved Images29 Interleaving  True Interleaving  False © roboVITics | Mayank Prasad, 2012
  • 30. Step, Data & ROI30  widthStep contains number of bytes between elements of same column and successive rows  imageData contains pointer to the first row of the image data  IplROI defines the practical Region of Interest  Contains xOffset, yOffset, height, width, coi  COI means Channel of Interest, though not respected by all OpenCV functions © roboVITics | Mayank Prasad, 2012
  • 31. Accessing Image Data31  All tasks may not have prepackaged well- optimized subroutine in OpenCV  So we need to access each pixel of the image sequentially  So, we need to handle the pointers ourselves  widthStep can be used in bytes “as is” without worrying because the data pointer is always of byte type © roboVITics | Mayank Prasad, 2012
  • 32. Accessing Image Data – Example32 © roboVITics | Mayank Prasad, 2012
  • 33. ROI & widthStep33  ROI stands for Region Of Interest  widthStep is the size in bytes between a pixel and the pixel vertically below it  In other words, widthStep refers to the size of a row in bytes © roboVITics | Mayank Prasad, 2012
  • 34. 34 Matrix & Image Operators Different Types of Matrix Operators © roboVITics | Mayank Prasad, 2012
  • 35. Matrix & Image Operators35  A variety of routines are available for matrix manipulation, most of which work equally well for images  They do most of the usual as well as complicated things  E.g. cvAdd(), cvAddS(), cvCvtColor(), cvSe t(), cvTranspose(), etc. © roboVITics | Mayank Prasad, 2012
  • 36. Acknowledments36 References Image Courtesy  Gary Bradski and  Gary Bradski and Adrian Adrian Kaehler, Learning Kaehler, Learning OpenCV, O’Reilly OpenCV, O’Reilly Media, Inc. Media, Inc. © roboVITics | Mayank Prasad, 2012
  • 37. UP NEXTImage Processing Techniques using OpenCV
  • 38. Contacts38  Mayank Prasad President, roboVITics mayank@robovitics.in  Akshat Wahi Asst. Project Manager, roboVITics +91 909 250 3053 akshat@core.robovitics.in  Akash Kashyap President, TEC – The Electronics Club of VIT akash130791@gmail.com © roboVITics | Mayank Prasad, 2012