Wednesday, 5 March 2014

JavaCV Tutorial 6 -Moments


This is the Coding Part of JavaCV-6 tutorial. In this tutorial I've briefly explained the concept " moments ". Moments are calculated using formula:
Here p is the x-order and q is the y-order, whereby order means the power to which the corresponding component is taken in the sum just displayed. The summation is over all of the pixels of the contour boundary (denoted by n in the equation). It then follows immediately that if p and q are both equal to 0, then the m00 moment is actually just the length in pixels of the contour.

The function that computes these moments for us is
void cvContoursMoments(
                                          CvSeq contour,
                                          CvMoments moments
                                           );


The first argument is the contour we are interested in and the second is a pointer to a structure that we must allocate to hold the return data. The CvMoments structure is defined as follows:

typedef struct CvMoments {


// spatial moments
double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03;


// central moments
double mu20, mu11, mu02, mu30, mu21, mu12, mu03;


// m00 != 0 ? 1/sqrt(m00) : 0
double inv_sqrt_m00;


} CvMoments;


The spatial moments give information about the object in the image, i.e. related (dependent) on the object position.

The central moments are adjusted for translational invariance, by moving the origin of the "coordinate system" used for calculations to the centroid (center of gravity) of the object in question.

The central normalized moments are scaled by the area of the object, and are thus scale invariant in addition to translational invariance.


double cvGetCentralMoment(
                                               CvMoments* moments,
                                               int x_order,
                                               int y_order
                                                );



double cvGetSpatialMoment(
                                              CvMoments* moments,
                                              int x_order,
                                              int y_order
                                               );


double cvGetNormalizedCentralMoment(
                                              CvMoments* moments,
                                              int x_order,
                                              int y_order
                                              );


void cvGetHuMoments(
                                             CvMoments* moments,
                                             CvHuMoments* HuMoments
                                      );


Source Code: " https://drive.google.com/file/d/0Bxr1St4kFOnQQ3lBRGt0a1FQQUU/edit?usp=sharing "


5 comments:

  1. Sir your tutorial are really useful thank you. can you post help like source site, source code or any useful information on hand gesture recognition??

    ReplyDelete
    Replies
    1. I 'll be doing tutorials on hand gesture recognition very soon. But if you want info about the hand gesture recognition u can visit javacv homepage, there u will find some info about convex defects and detection. With those info u can try to write your own code for hand gesture recognition.
      https://groups.google.com/forum/#!topic/javacv/lfUyejUi31c

      Delete
  2. if i want to find Z corresponding , how can i do?

    ReplyDelete
    Replies
    1. Currently I am working on that concept itself for one of my friends' project requirements, I'll be sure to update it when I am done ........

      Delete
  3. Hello Manoj, very helpful tutorials.
    Any idea on how to get the captured webcam in the context of a Swing component such as a JPanel or JLabel or JButton not in a CanvasFrame object or using cvNamedWindow method?

    ReplyDelete