FitEllipse opencv-python > 4

Viewed 2234

I'm having a quite big issue with fitellipse and opencv-python.

I know that I have to install opencv-contrib-python to get some functions but it doesn't work with fitellips function.

when using :

import cv2
cv2.fitEllipse()

here is the result:

TypeError: fitEllipse() missing required argument 'points' (pos 1)

but if now I try it using, for example, contour detection from an image:

img = cv2.imread('messi5.jpg',0)
retz,bawgray=cv2.threshold(img , 110,255,cv2.THRESH_BINARY)
contours,hierarchy = cv2.findContours(bawgray,1,1)
cnt = contours
big_contour = []
maxop = 0
for i in cnt:
    areas = cv2.contourArea(i) 
    if areas > maxop:
        maxop = areas
        big_contour = i 
img=cv2.drawContours(img, big_contour, -1, (0,255,0), 3)
cv2.FitEllipse(big_contour)

here is the result:

AttributeError: module 'cv2.cv2' has no attribute 'FitEllipse'

I use opencv-python 4.2.0.34 and opencv-contrib-python 4.2.0.34

1 Answers

You have not provided output for cv2.fitEllipse. Also you have misspelled the name. It is "fitEllipse" not "FitEllipse" with lower case "f".

Try

result = img.copy()
((centx,centy), (width,height), angle) = cv2.fitEllipse(big_contour)
cv2.ellipse(result, (int(centx),int(centy)), (int(width2/),int(height2/)), angle, 0, 360, (0,0,255), 1)
Related