Tuesday, March 25, 2014

JavaCV Tutorial 6 -Virtual Mouse



In this tutorial I have explained about controlling a mouse with some simple hand gestures. You can use this technique to either control a mouse or input the coordinate values to a microcontroller- servos to move a webcam in the direction of the object and so on.

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

Wednesday, March 5, 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 "