1

I am using EmguCV (a C# wrapper of OpenCV) and I can find contours using FindContours as:

        Contour<Point> cnts;
        cnts = imgLineMask.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST);

        for (; cnts != null; cnts = cnts.HNext)
        {
            double ar = cnts.Area;
        }

However, their area and moments are all zero if the contours are just one or two pixels big. Is there anyway to make it work with such small contours? Or it just simply can not work with very small contours?

Thanks

NESHOM
  • 899
  • 16
  • 46
  • Is the image black and white? Did you run hough transform before? – Gilad Jan 19 '15 at 06:47
  • Yes, it is a binary image with black background and white 2-3 tiny contours. No I did not apply hough transform. Should I do that? FindContours has no issue with larger contours. – NESHOM Jan 19 '15 at 15:55
  • In the examples opencv applys hough or threshold or something before find contours – Gilad Jan 19 '15 at 17:28

1 Answers1

2

No, I don't think there's a way to make it work, using Findcontours.

The reason is that the OpenCV method, is a contour finding method and not a blob finding method. The area is calculated from the perimeter and not just a sum of pixels.

The perimeter is a sum of the distance between neighboor pixels on the contour. Therefore the perimeter of a 2x2 pixel blob is 4, but the area will be 1 times 1 = 1. And a single pixel will have a perimeter of 0 and thus also an area of 0.

If you want to find single pixel blobs, you can have a look at the Recursive Grass-Fire algoritm or the Connected-Component algorithm. The latter is probably the easiest to implement.

Community
  • 1
  • 1
Anders
  • 580
  • 5
  • 19