1 | initial version |
Well, according to their documentation you can calculate the moment using
Imgproc.moments(Mat array)
This returns a Moment
type.
I have not used the Java API but after glancing through their documentation, the relative Java code is
List<Moments> contMoments = new ArrayList<Moments>();
// I made this a double instead of an int because of (1)
double sumOfMoments = 0, mass = 0;
for(int i = 0; i < contors.size(); ++i)
{
Moments thisMoment = Improc.moments(contours[i]);
sumOfMoments += thisMoment.get_m10();
mass += thisMoment.get_m00();
// (1) .get_m00() and .get_m10() both return doubles
contMoments.add(thisMoment); // finally add it to your collection
}
Here's the moments class
Always refer to the documentation.
Happy coding,
Cheers :)
2 | No.2 Revision |
Well, according to their documentation you can calculate the moment using
Imgproc.moments(Mat array)
or
Imgproc.moments(Mat array, boolean binaryImage)
This returns a Moment
type.
I have not used the Java API but after glancing through their documentation, the relative Java code is
List<Moments> contMoments = new ArrayList<Moments>();
// I made this a double instead of an int because of (1)
double sumOfMoments = 0, mass = 0;
for(int i = 0; i < contors.size(); ++i)
{
Moments thisMoment = Improc.moments(contours[i]);
sumOfMoments += thisMoment.get_m10();
mass += thisMoment.get_m00();
// (1) .get_m00() and .get_m10() both return doubles
contMoments.add(thisMoment); // finally add it to your collection
}
Here's the moments class
Always refer to the documentation.
Happy coding,
Cheers :)