1 | initial version |
Take a look at this tutorial:
http://opencv-code.com/tutorials/detecting-simple-shapes-in-an-image/
Given some contours, the program approximate a polygonal curve for that contours. This polygonal curve is the key for detecting the contour’s shape.
A contour is a circle if:
I have modified this tutorial in order to add a pre-processing step in order to build a robust algorithm to deal with different illumination conditions [1]. Afterwards, I run several times the canny detector with different parameters. The last step to detect all contours is to put together the same contours (two contours are the same contour is their center of mass is the same: the euclidean distance between the center of gravity is less than 1/2/3/4/ pixels depending on the size of the image).
[1] you can use this preprocessing algorithm https://github.com/bytefish/opencv/blob/master/misc/tan_triggs.cpp or even, you can use histogram equalization, or CLAHE (http://answers.opencv.org/question/12024/use-of-clahe/)
You can see the results I get:
2 | No.2 Revision |
I agree with LorenaGdL:
I don't think it is the appropiate function (I'm not even sure it will work at all if the blob is too different). To determine how much like a circle your contour is, you'd better use shape descriptors like compactness, elongation, convexity, moments, etc.
Take a look at this tutorial:
http://opencv-code.com/tutorials/detecting-simple-shapes-in-an-image/
Given some contours, the program approximate a polygonal curve for that contours. This polygonal curve is the key for detecting the contour’s shape.
A contour is a circle if:
I have modified this tutorial in order to add a pre-processing step in order to build a robust algorithm to deal with different illumination conditions [1]. Afterwards, I run several times the canny detector with different parameters. The last step to detect all contours is to put together the same contours (two contours are the same contour is their center of mass is the same: the euclidean distance between the center of gravity is less than 1/2/3/4/ pixels depending on the size of the image).
[1] you can use this preprocessing algorithm https://github.com/bytefish/opencv/blob/master/misc/tan_triggs.cpp or even, you can use histogram equalization, or CLAHE (http://answers.opencv.org/question/12024/use-of-clahe/)
You can see the results I get: