HandGesture Detection

*爱你&永不变心* 提交于 2021-02-17 05:17:12

问题


When I run this:

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

I get this error:

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

I have also tried:

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

and:

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

and got this error:

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)

回答1:


This is a difference between OpenCV 3.x and 4.x. In 3.x there were three return values, in 4.x there are only two. As the others mentioned, you only catch contours and hierarchy:

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

Alternatively, you can downgrade your OpenCV version, if what you actually want is to use 3.x.




回答2:


cv2.findContours() return two values and cannot be unpacked to contours, hierarchy and _

It should be like this:

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

or more:

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



来源:https://stackoverflow.com/questions/55411176/handgesture-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!