I have a webcam feed using OpenCV, and I am trying to fit an ellipse in real time.
The code I am using at the moment works, but it fails to fit an ellipse to the image a lot of the time. What other methods of ellipse fitting to an image can I pursue?
def find_ellipses(img): #img is grayscale image of what I want to fit ret,thresh = cv2.threshold(img,127,255,0) _,contours,hierarchy = cv2.findContours(thresh, 1, 2) if len(contours) != 0: for cont in contours: if len(cont) < 5: break elps = cv2.fitEllipse(cont) return elps #only returns one ellipse for now return None
elps is of the form
Here is an example of what I want to successfully fit an ellipse to. My current code fails with this image when I don't want it to.