findContours and drawContours for binary picture

asked 2020-04-24 13:01:32 -0500

Mr. D gravatar image

updated 2020-04-24 22:23:00 -0500

supra56 gravatar image

I created a binary picture with cv2.threshhold:

ret,thresh_img = cv2.threshold(original_img,127,255,cv2.THRESH_BINARY)

amd mow I want to use findContours() on that image and drawContours() on the original image.

I tried

contours = cv2.findContours(thresh_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img, contours, -1, (0, 255, 0), 3)

but I got a "TypeError: contours is not a numpy array, neither a scalar".

edit retag flag offensive close merge delete

Comments

It should be like this: cv2.drawContours(img,[contours], -1, (0, 255, 0), 3)

supra56 gravatar imagesupra56 ( 2020-04-24 22:36:33 -0500 )edit
1

please look up findContours() docs, it returns a (contours, hierarchy) tuple

berak gravatar imageberak ( 2020-04-25 01:41:41 -0500 )edit