报错信息:
Traceback (most recent call last):
File "***.py", line 47, in <module>
(x, y, w, h) = cv2.boundingRect(contour)
cv2.error: OpenCV(4.0.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/shapedescr.cpp:741: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'pointSetBoundingRect'
修改办法:
contours = contours[0] if imutils.is_cv2() else contours[1]
改为:
contours = contours[0]
可能原因:opencv版本问题。