Python says I have only two values and need three while there are already three values

时间:2019-04-16 23:52:27

标签: python-3.x opencv

(_,contours,hierarchy)=cv2.findContours(yellow, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)

The code here throws an error saying that I am missing the third value but it already has three values

yellow = 1.  
cv2.RETR_TREE = 2.  
cv2.CHAIN_APROX_SIMPLE = 3.  

and I don't know what to do.

I define yellow as

yellow = cv2.inRange(hsv, yellow_lower, yellow_upper)

and both yellow_lower and yellow_upper are defined...

Can anybody help? Thanks in advance

1 个答案:

答案 0 :(得分:0)

您相信将返回三个值(第一个值将被丢弃):

_, contours, hierarchy = cv2.findContours(yellow, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

诊断告诉您只有两个返回。 因此,接受它们两者:

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

您似乎正在使用主版本号为2的downrev cv2库。 在3.x版本中,签名被更改为将图像作为第三个返回值。