If I have a 3x3 binary image and there is a contour in locations(x,y): (0,0), (0,1), (1,0), (1,1)
I get the contour via findContours
method.
I want to get this contour's area:
- with CountNonZero: 4
- with contourArea: 1
- with Moment M00: 1
What is the correct answer and what is the difference between them?
This contour is square so the area is 2*2 = 4
So why is ContourArea equal to 1?
I am using EmguCV and this is my code:
VectorOfVectorOfPoint cont = new VectorOfVectorOfPoint();
Image<Gray, byte> img = new Image<Gray, byte>(3,3);
img[0, 0] = new Gray(255);
img[0, 1] = new Gray(255);
img[1, 0] = new Gray(255);
img[1, 1] = new Gray(255);
CvInvoke.FindContours(img, cont, null, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
Moments m = CvInvoke.Moments(cont[0], true);
Console.WriteLine(CvInvoke.ContourArea(cont[0]));
CvInvoke.Imshow("ss", img);
CvInvoke.WaitKey(0);