手势检测

时间:2019-03-29 05:45:25

标签: python windows opencv

运行此命令时:

contours,_,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

我收到此错误:

ValueError: not enough values to unpack (expected 3, got 2)

我也尝试过:

_, contours,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

和:

contours,hierarchy,_ = cv2.findContours(thresh.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

并收到此错误:

Traceback (most recent call last):
  File "C:/Users/HASHMATI/AppData/Local/Programs/Python/Python37-32/new2hand.py", line 152, in <module>
    gestureRecognition(frame,roi_rect,frame[y:y+h, x:x+w])
  File "C:/Users/HASHMATI/AppData/Local/Programs/Python/Python37-32/new2hand.py", line 99, in gestureRecognition
    detectGesture(src,roi_rect,img_dilated)
  File "C:/Users/HASHMATI/AppData/Local/Programs/Python/Python37-32/new2hand.py", line 21, in detectGesture
    contours,_,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
ValueError: not enough values to unpack (expected 3, got 2)

2 个答案:

答案 0 :(得分:1)

cv2.findContours()返回两个值,不能解压到轮廓,层次结构和_

应该是这样的:

contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

或更多:

a, b, *others = [1, 2, 3, 4]

答案 1 :(得分:0)

这是OpenCV 3.x和4.x之间的区别。在3.x中有三个返回值,在4.x中只有两个。正如其他人提到的那样,您仅捕获contourshierarchy

contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

或者,如果实际需要使用3.x,则可以降级OpenCV版本。

相关问题