Mayank Bansal
Mayank Bansal

Reputation: 1125

Detect an arc from an image contour or edge

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

Upvotes: 3

Views: 7403

Answers (3)

pr3sidentspence
pr3sidentspence

Reputation: 532

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

Upvotes: 2

Michael Kupchick
Michael Kupchick

Reputation: 443

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.

Upvotes: 2

skm
skm

Reputation: 5659

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.

Upvotes: 3

Related Questions