Open jarredcutlip opened 4 years ago
firstly, it should be key=cv2.contourArea. And what it seems is that contours is a float type of array, whereas it should be int type. I am not exactly sure as to why that is happening.
This is due to syntax changes in OpenCV 4.
Change
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]
This is due to syntax changes in OpenCV 4. Change
contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]
tocontours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[0]
This Also solves a similar issue in fun_util.py which needs to be changed based on the opencv version being used
Line 102: contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[0]
Traceback (most recent call last): File "create_gestures.py", line 106, in store_images(g_id) File "create_gestures.py", line 70, in store_images contour = max(contours, key = cv2.contourArea(contours[0])) cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:274: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'
Do you have any idea about this error ? I tried googling it but there was no solution.