Ananda
Ananda

Reputation: 3272

Error is using opencv with python

I have this code for finding contour in opencv with python

im = cv2.imread('test.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

When I try to run this I am getting an error saying

"ValueError: need more than two values to unpack"

Any help is appreciated.

Upvotes: 0

Views: 52

Answers (1)

ZdaR
ZdaR

Reputation: 22954

Actually there is some documentation mismatch of cv2.findcontours() method, it simple returns 2 values: contours, hierarchy, so you should replace the last line with :

contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

Upvotes: 1

Related Questions