Ellipse setting anomaly when using cv2.ellipse with different parameters?

I am using OpenCV 2.4.11 with Python 2.7.9 on Windows 8.1. I was trying to paint ellipses on my paths and I came across something I can't figure out.

When I call cv2.fitEllipse and get the return value and then pass the return value directly to cv2.ellipse with the following code, the ellipses drawn on the screen are perfect and fit my paths optimally:

contours, hierarchy = cv2.findContours(binaryimage,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

for ind, cont in enumerate(contours):
    elps = cv2.fitEllipse(cont)
    #Feed elps directly into cv2.ellipse
    cv2.ellipse(displayframe,elps,(0,0,255))

cv2.imshow("Perfectly fitted ellipses", displayframe)

      

Results for the above

enter image description here

However, when I try to parse the actual parameters of the ellipse and draw the ellipse manually by passing those parameters (see code below), it creates a "bloated" version of the ellipse, which gives a very convenient (but annoying) space brace around the path, like this:

contours, hierarchy = cv2.findContours(binaryimage,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

for ind, cont in enumerate(contours):
    (x,y),(MA,ma),angle = cv2.fitEllipse(cont)
    #feed the parsed parameters into cv2.ellipse
    cv2.ellipse(displayframe,(x,y),(MA, ma),angle,0,360,(0,0,255))

cv2.imshow("Ellipses NOT fitting the contours properly",displayframe)

      

Results for this annoying phenomenon:

enter image description here

Yes, I know that using the first method solves the problem of drawing correct ellipses. But I want to know why it does this, because I actually need the ellipse parameters to do some kind of blob tracking, and if the parsed parameters end up giving wide unusable ellipses, is this really accurate? Problem with cv2.ellipse () function? Any ideas on what is going wrong? Exact ellipse parameters coming out of cv2.fitEllipse function?

+3


source to share


1 answer


You are drawing the width and height of the returned bounding rectangle. You should plot the width and height half as the axes of the ellipse will be half the width and height of its bounding rectangle



cv2.ellipse(displayframe,(x,y),(MA/2, ma/2),angle,0,360,(0,0,255))

      

+4


source







All Articles