Tag Archives: Opencv edge detection error

[Solved] Opencv edge detection error: OpenCV(4.1.1) error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth ==…

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]

Error:
OpenCV(4.1.1) error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function ‘cv::contourArea’

Solution:
Wrong operation here:
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
If you still want to use it, you can change it to:
cnts = cnts[1] if imutils.is_cv3() else cnts[0]