I'm currently reading through the example code on the OpenCV website tyring to find contours in an image.
I first read an image and convert to gray-scale:
img = cv2.imread('/.../.../four.png')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
I then convert the image into binary by applying a threshold:
thresh = cv2.threshold(imgray, 127, 255, 0, cv2.THRESH_BINARY)
According to the tutorials.. I should then be able to call findContours() on the thresholded image:
contours = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
When trying to execute this code, for some reason i'm getting a type error:
contours = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) TypeError: image is not a numerical tuple
Unsure why?
Here's the full code for easier readability:
img = cv2.imread('/Users/samtozer/Desktop/four.png')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(imgray, 127, 255, 0, cv2.THRESH_BINARY)
contours = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0,255,0), 3)
Wondering if anyone has experienced this problem before? And if so, what is going wrong xD
Thanks in advance
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)- Jeru Lukeprint contours? - Jeru LukefindContours) - user6845426ret, thresh = cv2.threshold(imgray, 127, 255, 0, cv2.THRESH_BINARY). Becausecv2.thresholdreturns a tuple - Jeru Luke