# ellipse detection

Hello, I have a question regarding the detection of ellipses in an image.

This sample ("http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rotated_ellipses/bounding_rotated_ellipses.html") I have found already, but it detects not only ellipses but also other counturs. Is there any way to modify this? Ans the fitEllipse method want an InputArray as parameter, but I am not quite sure how I should achieve this? In general, are there any faster methods for ellipse detection?

I am relative new with OpenCV and hope my question is not too stupid.

Kind regards, Simon Rühle

edit retag close merge delete

2

fitEllipse does not detect ellipses, it fits the best matching one to a pointset

( 2014-01-17 15:20:28 -0500 )edit

Your are right, I expressed that a little bit wrong. The question was how I could achieve an detection of (only) ellipses with this method. I am not sure how I can generate the array the method needs

( 2014-01-19 09:24:29 -0500 )edit

Sort by » oldest newest most voted

This should be possible. fitEllipse will return a RotatedRect type, which contains

• Point2f center
• Size2f size
• float angle

Using the center and angle, you re-center and un-rotate your points:

1. points = points - center
2. points = inv_R * points;

Your points will be centered at (0,0).

Now, if your points are truly ellipse then they should fit the ellipse equation closely:

float a = size.width * 0.5;
float b = size.height * 0.5;

x^2/a^2 + y^2/b^2 = 1


a and b might be swapped depending on the convention. Count how many points are "close" to 1, based on some experimental threshold. Or you can try something more sophisticated like finding the nearest distance to an ellipse in pixels (I have no idea what the formula is).

more

Official site

GitHub

Wiki

Documentation