4 ms·
I once wrote a similar OpenCV application [1], but in my case I needed to detect a closed contour and evaluate how close that contour was to being a circle. To
by elteto 10y ago
I once wrote a similar OpenCV application [1], but in my case I needed to detect a closed contour and evaluate how close that contour was to being a circle. To provide a "score" I took advantage of the fact that in a circle the ratio C^2/(4piA) = 1 (where C is the circumference and A is the area). This is a unique property of the circle (it is equivalent to saying that the ratio of perimeter to area is maximized in a circle) and it's always lower for any other closed shapes. And it also provides a nice 0..1 result which can be interpreted as a percentage score!
I followed pretty much the same image segmentation/binary threshold as in the article, but found that the gaussian blur step was unnecessary in my case, so I skipped it. Also, the closed contours API in OpenCV provides the area and perimeter results so it was very easy to get it all working. Most of the code was actually just writing a simple UI in Python.
[1] https://www.youtube.com/watch?v=iN6D5j2RfX0 https://www.youtube.com/watch?v=iN6D5j2RfX0