OpenCV_python 大神们求解----OpenCV对检测的轮廓进行体积排序问题

veryme3 2020-03-13 12:20:11
大神们,求解

错误提示: cnts = sorted(cnts, key=cv.contourArea, reverse=True)[:5]
cv2.error: OpenCV(4.2.0) C:\projects\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'

在提取轮廓后,想对轮廓由轮廓面积大小进行排序,但一直报错

百度找了好久也没找到解决办法

...全文
482 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
点yolo1024 2021-12-14
  • 打赏
  • 举报
回复

你好 请问怎么解决的

E艺恩N 2021-02-21
  • 打赏
  • 举报
回复
解决啦,赞赞赞!
lhlc67 2020-07-14
  • 打赏
  • 举报
回复 3
cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[0] 把最后那个1改为0就可以了 Remember that in Opencv4 cv2.findContour() only returns 2 values: contours, hierachy https://docs.opencv.org/master/d4/d73/tutorial_py_contours_begin.html. So it should be cnts = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[0]

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧