Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If the object is a circle (not ellipse), try the circular Hough transform on the contours of the object.

Otherwise you can implement a RANSAC detector. It's not part of OpenCV, but it's fairly simple: select a few random points on the contour, fit an ellipse*, then count the number of contour points that are on the ellipse. Then repeat this many times, and select the solution that has the most contour points on the ellipse.

*To fit an ellipse on random points, select 6 points on the contour and solve the equation:

ax²+bxy+cy²+dx+ey+f=0

for each (x,y). Then, when you have determined the 6 parameters (a,b,c,d,e,f), take every contour point and see if it verifies the equation above.