简体   繁体   English

FitEllipse opencv-python > 4

[英]FitEllipse opencv-python > 4

I'm having a quite big issue with fitellipse and opencv-python.我对 fitellipse 和 opencv-python 有一个很大的问题。

I know that I have to install opencv-contrib-python to get some functions but it doesn't work with fitellips function.我知道我必须安装 opencv-contrib-python 才能获得一些功能,但它不适用于 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我使用 opencv-python 4.2.0.34 和 opencv-contrib-python 4.2.0.34

You have not provided output for cv2.fitEllipse.您尚未为 cv2.fitEllipse 提供 output。 Also you have misspelled the name.你也拼错了名字。 It is "fitEllipse" not "FitEllipse" with lower case "f".它是“fitEllipse”而不是带有小写“f”的“FitEllipse”。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM