我在 fitellipse 和 opencv-python 方面遇到了很大的问题。
我知道我必须安装 opencv-contrib-python 才能获得一些功能,但它不适用于 fitellips 函数。
使用时:
import cv2
cv2.fitEllipse()
Run Code Online (Sandbox Code Playgroud)
这是结果:
TypeError: fitEllipse() missing required argument 'points' (pos 1)
Run Code Online (Sandbox Code Playgroud)
但如果现在我尝试使用例如图像的轮廓检测:
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)
Run Code Online (Sandbox Code Playgroud)
这是结果:
AttributeError: module 'cv2.cv2' has no attribute 'FitEllipse'
Run Code Online (Sandbox Code Playgroud)
我使用 opencv-python 4.2.0.34 和 opencv-contrib-python 4.2.0.34
您尚未提供 cv2.fitEllipse 的输出。而且你的名字也拼错了。它是“fitEllipse”而不是小写“f”的“FitEllipse”。
尝试
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3698 次 |
| 最近记录: |