大神們,求解
錯誤提示: 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'
在提取輪廓后,想對輪廓由輪廓面積大小進行排序,但一直報錯
百度找了好久也沒找到解決辦法

uj5u.com熱心網友回復:
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]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/24849.html
上一篇:【NAS with RL】2017-ICLR-Neural Architecture Search with Reinforcement Learning-論文閱讀
