【踩坑记录】Opencv提取轮廓时出错

【踩坑记录】Opencv提取轮廓时出错,第1张

报错代码

这里就是想提取一下轮廓,谁知道就崩了呢?!:

# 轮廓检测
cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[1]
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]

-错误提示

提示:Traceback (most recent call last): cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:315: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function ‘cv::contourArea’


解决方案:

提示:将 findContours(...)[1] 改为findContours(...)[0]

错误原因:应该是opencv的版本不同导致的

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/905392.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-15
下一篇2022-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存