3

I am trying to detect arcs inside an image. The information that I have for certain with me is the radius of the arc. I can try and maybe get the centre of the circle whose arc I want to identify.

Is there any algorithm in Open CV which can tell us that the detected contour ( or edge from canny edge is an arc or an approximation of an arc)

Any help on how this would be possible in OpenCV with Python or even a general approach would be very helpful

Thanks

Mayank Bansal
  • 1,095
  • 1
  • 10
  • 12

3 Answers3

3

If you think that there will not be any change in the shape (i mean arc won't become line or something like this) then you can have a look a Generalized Hough Transform (GHT) which can detect any shape you want.

Cons:

  • There is no directly function in openCV library for GHT but you can get several source code at internet.

  • It is sometimes slow but can become fast if you set the parameters properly.

  • It won't be able to detect if the shape changes. for exmaple, i tried to detect squares using GHT and i got good results but when square were not perfect squares (i.e. rectangle or something like that), it didn't detect.

skm
  • 5,015
  • 8
  • 43
  • 104
  • Ok, I will try it out I had seen it earlier, but have been worried about trying it out as I am working on a video in which I am trying to identify elliptical objects, the brightness and positon keeps on changing throughout – Mayank Bansal Feb 24 '14 at 12:23
  • ok, if your source of images is a webcam then i think that GHT would not be a good option because scale/size/orientation won't be a problem but the shape would definitely be. – skm Feb 24 '14 at 13:31
  • Its a HD video recording that I am working with Ya, the shape and orientation keeps on changing throughout the video – Mayank Bansal Feb 24 '14 at 14:13
  • as i mentioned, orientation change won't be a problem but changing shape will be a problem. – skm Feb 24 '14 at 14:20
2

You can do it this way:

  1. Convert the image to edges using canny filter.
  2. Make the image binary using threshold function there is an option for regular threshold, otsu or adaptive.
  3. Find contours with sufficient length (findContours function)
  4. Iterate all the contours and try to fit ellipse (fitEllipse function)
  5. Validate fitted ellipses by radius.
  6. Check if detected ellipse is good fit - checking how much of the contour pixels are on the detected ellipse. Select the best one.

You can try to increase the speed using RANSAC each time selecting 6 points from binarized image and trying to fit.

Michael Kupchick
  • 433
  • 2
  • 10
  • Thanks for the approach, I have tried doing something like that it returns me way too many ellipses I will explore RANSAC, don't have much idea about it – Mayank Bansal Feb 27 '14 at 06:55
2

My math is rusty, but...

What about evaluating a contour by looping over its composite edge-nodes and finding those where the angle between the edges doesn't change too rapidly AND doesn't change sign?

A chain of angles (θ) where:

0 < θi < θmax

with number of edges (c) where:

c > dconst

would indicate an arc of:

radius ∝ 1/(θi + θi+1 + ...+ θn)/n)

or:

r ∝ 1/θave

and:

arclenth ∝ c

A way of finding these angles is discussed at Get angle from OpenCV Canny edge detector

pr3sidentspence
  • 502
  • 4
  • 14