Ask Your Question

Revision history [back]

fitellipse not fitting

I get this result when fitting an ellipse to a contour (the contour is green, the fitted ellipse in blue) image description

Here's the original image : image description

Why doesn't it fit? Here is the code :


img1 = cv2.imread(r'limb_edge_fl28_iss3628.jpg')

gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

Threshold the images

thresh1 = cv2.threshold(gray1, 127, 255, cv2.THRESH_BINARY)[1]

contours = cv2.findContours(thresh1.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[1]

cnt1 = contours[0]

draw contours found

cv2.drawContours(img1, [cnt1], 0, green, 2)

Fit an ellipse to the contours

ellipse = cv2.fitEllipse(cnt1)

Draw the ellipse on the image

cv2.ellipse(img1,ellipse,(255,255,0),2)

cv2.imshow("ellipse fit 1", img1)

fitellipse not fitting

I get this result when fitting an ellipse to a contour (the contour is green, the fitted ellipse in blue) image description

Here's the original image : :

image description

Why doesn't it fit?

Here is the code :


----------
img1 = cv2.imread(r'limb_edge_fl28_iss3628.jpg')

cv2.imread(r'limb_edge_fl28_iss3628.jpg')

gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

cv2.COLOR_BGR2GRAY)

# Threshold the images

images thresh1 = cv2.threshold(gray1, 127, 255, cv2.THRESH_BINARY)[1]

cv2.THRESH_BINARY)[1]

contours = cv2.findContours(thresh1.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[1]

cv2.CHAIN_APPROX_NONE)[1]

cnt1 = contours[0]

contours[0]

# draw contours found

found cv2.drawContours(img1, [cnt1], 0, green, 2)

2)

# Fit an ellipse to the contours

contours ellipse = cv2.fitEllipse(cnt1)

ellipse = cv2.fitEllipse(cnt1)

# Draw the ellipse on the image

image cv2.ellipse(img1,ellipse,(255,255,0),2)

cv2.ellipse(img1,ellipse,(255,255,0),2)

cv2.imshow("ellipse fit 1", img1)

img1)