Ask Your Question
1

ellipse detection

asked Jan 17 '14

S42 gravatar image

updated Oct 5 '15

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

Preview: (hide)

Comments

2

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

berak gravatar imageberak (Jan 17 '14)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 (Jan 19 '14)edit

1 answer

Sort by » oldest newest most voted
4

answered Jan 20 '14

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

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Jan 17 '14

Seen: 7,485 times

Last updated: Jan 20 '14