1 | initial version |
you could try
Imgproc.findContours(temp, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
for (int idx = 0; idx < contours.size(); idx++)
{
MatOfPoint contour = contours.get(idx);
Moments moment = Imgproc.moments(contour);
double area = moment.m00;
System.out.print( area );
}
2 | No.2 Revision |
you could try
import org.opencv.imgproc.Moments; // you should have this line to use Moments
.
.
.
Imgproc.findContours(temp, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
for (int idx = 0; idx < contours.size(); idx++)
{
MatOfPoint contour = contours.get(idx);
Moments moment = Imgproc.moments(contour);
double area = moment.m00;
System.out.print( area );
}
3 | No.3 Revision |
you could try
import org.opencv.imgproc.Moments; // you should have this line to use Moments
.
.
.
Imgproc.findContours(temp, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
for (int idx = 0; idx < contours.size(); idx++)
{
MatOfPoint contour = contours.get(idx);
Moments moment = Imgproc.moments(contour);
double area = moment.m00;
System.out.print( area );
}
or if your main need is only to calculate area
for (int idx = 0; idx < contours.size(); idx++)
{
MatOfPoint contour = contours.get(idx);
double area = Imgproc.contourArea(contour);
System.out.print( area );
}