Ask Your Question
0

How to debug this error in python?

asked 2020-02-20 07:14:03 -0600

updated 2020-02-20 08:22:34 -0600

supra56 gravatar image

Line: contour[0] = max(contours, key = cv2.contourArea) 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.

thresh = thresh[y:y+h, x:x+w]
        contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]

        if len(contours) > 0:
            contour[0] = max(contours, key = cv2.contourArea)
            if cv2.contourArea(contour) > 10000 and frames > 50:
                x1, y1, w1, h1 = cv2.boundingRect(contour)
edit retag flag offensive close merge delete

Comments

I tested it OpenCV 4. Change this:

contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]

to:

contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[0]
supra56 gravatar imagesupra56 ( 2020-02-20 08:40:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-02-20 08:19:41 -0600

mvuori gravatar image

In Python, findContours returns contours AND hierarchy. Fix that line.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-02-20 07:14:03 -0600

Seen: 8,970 times

Last updated: Feb 20 '20