手势检测

2024-04-11

当我运行这个时:

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)

and:

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)

这是 OpenCV 3.x 和 4.x 之间的区别。在 3.x 中,有三个返回值,在 4.x 中只有两个。正如其他人提到的,你只能抓住contours and hierarchy:

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

手势检测 的相关文章

随机推荐