Ask Your Question
1

ellipse detection

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

S42 gravatar image

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

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 flag offensive close merge delete

Comments

2

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

berak gravatar imageberak ( 2014-01-17 15:20:28 -0600 )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 -0600 )edit

1 answer

Sort by » oldest newest most voted
4

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

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

Question Tools

1 follower

Stats

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

Seen: 7,348 times

Last updated: Jan 20 '14