Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to use python to detect ellipse

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: