# Finding a circle with a defective contour

Hello everyone, I need help with detecting defective circles and defective areas like shown on images below:

Above picture is a simplified example of what real problem would look like. Bad circle has indents or/and outdents.

And this pitcture displays the result I would like to get with OpenCV. So basically, outdents and indents are marked with one color and the area between good cirle line and defected line is marked with another color.

Algorithm I will hopefully make with your help would be applied to broken soda cans pictures like the one above.

So far I've been able to apply Hough Circle transform algorithm which works fine, but now I need help to find broken parts of circle (soda can) and to mark them. I assumed I would need to apply a countour detection and then somewhat calculate the difference between perfect circle and detected contour. But what I've noticed is that a findCountour function saves pixsel data as a set of each point of a contour while Hough circle transform saves pixsel data only for a circle center and not for circle ouotline, therefore I cannot simply subtract one from another to get that desired difference.

edit retag close merge delete

You can compute the pixel coordinates of the circle outline from the center/radius given by the Hough transform; so you can compare it with the contour given by findContour.

(x-xc)² + (y-yc)² = r²


so:

x = xc +/- sqrt(r²-(y-yc)²)


where xc and yc are the center coordinates and r the radius. Loop y from -r to r to get the x coordinates for each line.

( 2019-08-28 08:45:19 -0500 )edit