python-3.x - FitEllipse opencv-python > 4
问题描述
我对 fitellipse 和 opencv-python 有一个很大的问题。
我知道我必须安装 opencv-contrib-python 才能获得一些功能,但它不适用于 fitellips 功能。
使用时:
import cv2
cv2.fitEllipse()
结果如下:
TypeError: fitEllipse() missing required argument 'points' (pos 1)
但是如果现在我尝试使用例如从图像中检测轮廓:
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)
结果如下:
AttributeError: module 'cv2.cv2' has no attribute 'FitEllipse'
我使用 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)
推荐阅读
- django - 如何从 FileField django 下载文件
- xml - Maven 错误:“无法解析 com.github.ConnorLinfoot:ActionBarAPI:1.5.4”
- python - 使用 xpath 获取以字符串开头的 id
- javascript - 用于文件输入的 AngularJS 指令不更新 ngmodel
- javascript - AWS Amplify 在 graphql 突变后发送电子邮件
- c++ - 在模板类中继承类型别名
- ruby-on-rails - Rails - 输入的数据不显示
- rest - 哪个http动词/最佳实践来更新没有有效负载的实体?
- git - 来自项目根目录中另一个 git repo 的文件
- visual-studio - Visual Studio mac 中的“无效配置映射”