碎点篇——opencv边缘检测报错

返回主目录

opencv边缘检测报错

cnts = cv2.findContours(edged_image.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5]

报错: 


  OpenCV(4.1.1) error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'

解决方法:


  这里的操作有误:
  cnts = cnts[0] if imutils.is_cv2() else cnts[1]
  如果你仍然想使用它, 你可以将它改为:
  cnts = cnts[1] if imutils.is_cv3() else cnts[0]

             

返回主目录

发布了42 篇原创文章 · 获赞 15 · 访问量 2791

猜你喜欢

转载自blog.csdn.net/qq_38299170/article/details/103836519