Ask Your Question
0

how to use python to detect ellipse

asked 2016-08-18 21:14:45 -0600

tiantong gravatar image

I want to detect the simple shapes in an image. I use cv2.approxPolyDP to detect vertices, but the result of ellipse is 4, same as square, how to differ them? Or, how to detect an ellipse, given the contour?

This is part of the code, "c" is the contour. I find ellipse's approx is 4, same as square.

    shape = "unidentified"
    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.04 * peri, True)

    # if the shape is a triangle, it will have 3 vertices
    if len(approx) == 3:
        shape = "triangle"

    # if the shape has 4 vertices, it is either a square or
    # a rectangle
    elif len(approx) == 4:
edit retag flag offensive close merge delete

Comments

1

I think you can't do that just with approxPolyDP(). Instead you could use some circularity attributes (inertia ratio), take a look at this article. Another option would be to use scikit-image, which provides an elliptical hough transform, see here.

Missing gravatar imageMissing ( 2016-08-19 02:03:05 -0600 )edit

so, your concept hit a little wall there, no ? ;)

(counting corners on round things, hmmm)

berak gravatar imageberak ( 2016-08-19 05:15:19 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-08-19 06:35:39 -0600

supertramp-sid gravatar image

updated 2016-08-19 06:36:11 -0600

Just search the web, there are so many references. Depending on your situation you might find many ways to solve.
For example:
Hough Transform 1 .
Hough Transform Paper.
Using fit ellipse

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-18 21:14:45 -0600

Seen: 5,950 times

Last updated: Aug 19 '16