I tried to draw contour in the image, got error to solve.
import cv2
img = cv2.imread('image7.jpg')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('grey',imgray)
ret, thresh = cv2.threshold(imgray, 50, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
print("Number of contours = {}".format(str(len(contours))))
print('contours {}'.format(contours[0]))
cv2.drawContours(img, contours, -1, (0, 255, 0), 2)
cv2.drawContours(imgray, contours, -1, (0, 255, 0), 3)
cv2.imshow('Image', img)
cv2.imshow('Image GRAY', imgray)
cv2.waitKey(0)
This is the error message:
Error:
ValueError Traceback (most recent call last)
<ipython-input-1-e0ee08be0330> in <module>
6 ret, thresh = cv2.threshold(imgray, 50, 255, 0)
7
----> 8 contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
9 print("Number of contours = {}".format(str(len(contours))))
10 print('contours {}'.format(contours[0]))
ValueError: too many values to unpack (expected 2)