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]

posted @ 2019-09-18 17:48  万道一  阅读(4723)  评论(0编辑  收藏  举报