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]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM