Ask Your Question

ellipse detection

asked 2014-01-17 14:45:13 -0500

S42 gravatar image

updated 2015-10-05 15:13:53 -0500

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

This sample ("") 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 flag offensive close merge delete



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

berak gravatar imageberak ( 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

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

1 answer

Sort by » oldest newest most voted

answered 2014-01-20 00:49:07 -0500

Nghia gravatar image

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).

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-01-17 14:45:13 -0500

Seen: 6,508 times

Last updated: Jan 20 '14