-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Open
Labels
Description
System Information
OpenCV python version: 4.10.0
Operating System / Platform: Ubuntu 24.04.1 LTS
Python version: 3.12.3
Detailed description
cv2.fitEllipse function fails to fit an ellipse with a certain set of points. It seems that the returned angle of the ellipse should be around 90 degrees but 0 degree angle is returned instead.
I have added four examples: three sets of points for which ellipse fitting fails and one set of points for which ellipse is fitted successfully.
I am attaching the output of all four examples. No input is needed to reproduce the code. The points that need to be fitted are marked in red.
This might be related to issue #26078
Steps to reproduce
import numpy as np
import cv2
# This is an example where ellipse fitting fails
points_to_fit = np.array([[37,111],[37,112],[36,113],[37,114],[37,115],[37,116],[37,117],[37,118],[36,119],[35,120],[34,120],[33,121],[32,121],[31,121],[30,122],[29,123],[28,123],[27,124],[26,124],[25,125],[25,126],[25,127],[25,128],[25,129],[254,121],[255,120],[255,119],[256,118],[256,117],[256,116],[256,115],[256,114],[256,113],[256,112],[256,111],[256,110],[256,109],[256,108],[256,107],[257,106],[257,105],[256,104],[257,103],[257,102],[257,101]])
# This is another example where ellipse fitting fails (subset of points in the first example). Uncomment the line below to check
#points_to_fit = np.array([[ 37, 105], [ 38, 106], [ 38, 107], [25,129], [254,121], [257, 103], [257, 102], [257, 101]])
# This is another example where ellipse fitting fails (subset of points in the second example). Uncomment the line below to check
# points_to_fit = np.array([[ 37, 105], [ 38, 106], [ 38, 107], [257, 103], [257, 102], [257, 101]])
# This is a different set of point where ellipse is fitted successfully. Uncomment the line below to check
# points_to_fit = np.array([[ 30, 105], [ 25, 110], [ 30, 115], [250, 105], [255, 110], [250, 115]])
e = cv2.fitEllipse(np.array(points_to_fit))
print(e)
img_tmp = np.ones((300, 300, 3), np.uint8) * 255
img_tmp = cv2.ellipse(img_tmp, e, (0,0,0), 1, cv2.LINE_AA)
for point in points_to_fit:
img_tmp = cv2.circle(img_tmp, (int(round(point[0])), int(round(point[1]))), 1, (0,0,255), -1)
cv2.imshow("ellipse", img_tmp)
cv2.waitKey(0)
cv2.destroyAllWindows() Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
Reactions are currently unavailable



