Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to calculate HuMoments for a contour/image in opencv using c++

hi,

i tried out the following tutorial.I used opencv 2.4.2 with visual studio 2010 and c++.(http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html)

there i can calculate moments for each and every contour of the image, like this

vector<moments> mu(contours.size() ); for( int i = 0; i < contours.size(); i++ ) { mu[i] = moments( contours[i], false ); }

then i tried to calculate Hu-Moments in the same way. i tried with various combinations, but didn't got it work. My problems are,

  1. is it possible to calculate Hu-Moments only for a one contour ?
  2. should i calculate Hu-Moments for the whole image?

please can anyone explain this with some examples?

click to hide/show revision 2
make code better readable

How to calculate HuMoments for a contour/image in opencv using c++

hi,

i tried out the following tutorial.I used opencv 2.4.2 with visual studio 2010 and c++.(http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html)

there i can calculate moments for each and every contour of the image, like this

vector<moments>

vector<Moments> mu(contours.size() );
 for( int i = 0; i < contours.size(); i++ )
 {
    mu[i] = moments( contours[i], false );
     }

}

then i tried to calculate Hu-Moments in the same way. i tried with various combinations, but didn't got it work. My problems are,

  1. is it possible to calculate Hu-Moments only for a one contour ?
  2. should i calculate Hu-Moments for the whole image?

please can anyone explain this with some examples?

How to calculate HuMoments for a contour/image in opencv using c++

hi,

i tried out the following tutorial.I used opencv 2.4.2 with visual studio 2010 and c++.(http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html)

there i can calculate moments for each and every contour of the image, like this

vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ )
{
   mu[i] = moments( contours[i], false );
}

then i tried to calculate Hu-Moments in the same way. i tried with various combinations, but didn't got it work. My problems are,

  1. is it possible to calculate Hu-Moments only for a one contour ?
  2. should i calculate Hu-Moments for the whole image?

please can anyone explain this with some examples?

How to calculate HuMoments for a contour/image in opencv using c++

hi,

i tried out the following tutorial.I used opencv 2.4.2 with visual studio 2010 and c++.(http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html)

there i can calculate moments for each and every contour of the image, like this

vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ )
{
   mu[i] = moments( contours[i], false );
}

then i tried to calculate Hu-Moments in the same way. i tried with various combinations, but didn't got it work. My problems are,

  1. is it possible to calculate Hu-Moments only for a one contour ?
  2. should i calculate Hu-Moments for the whole image?

please can anyone explain this with some examples?