OpenCV Assertion failed: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S)

和自甴很熟 提交于 2019-12-05 19:49:10
Berriel

This is doing the wrong thing:

contours = contours[0] if imutils.is_cv2() else contours[1]

imutils.is_cv2() is returning False even though it should return True. If you don't mind to remove this dependency, change to:

contours = contours[0]

I found out the reason. Probably, the tutorial you are following was published before OpenCV 4 was released. OpenCV 3 changed cv2.findContours(...) to return image, contours, hierarchy, while OpenCV 2's cv2.findContours(...) and OpenCV 4's cv2.findContours(...) return contours, hierarchy. Therefore, before OpenCV 4, it was correct to say that if you use OpenCV 2 it should be contours[0] else contours[1]. If you still want to have this "compatibility", you can change to:

contours = contours[1] if imutils.is_cv3() else contours[0]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!