首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV python: ValueError:太多的值无法解包,img

OpenCV python: ValueError:太多的值无法解包,img
EN

Stack Overflow用户
提问于 2022-02-12 14:26:13
回答 4查看 934关注 0票数 -1

我正在写一个opencv项目,它是一个手指测距仪和一个图像(它的解释很复杂,但我尽力了。)

当我运行这个脚本时,我会得到这个错误

代码语言:javascript
复制
Traceback (most recent call last):
  File "D:/P4rakash_Python_Projects/Python Projects/adding things/python.py", line 16, in <module>
    hands, img2 = detector.findHands(img)
ValueError: too many values to unpack (expected 2)
[ WARN:0] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

我不明白这个错误,如果有人修理它,并回答我,我可以把它的窍门。

这是完整的代码

代码语言:javascript
复制
from cv2 import cv2
from cvzone.HandTrackingModule import HandDetector

cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)

detector = HandDetector(detectionCon=0.8)

startDist = None

scale = 0.
cx, cy = 500, 500
while True:
    Success, img = cap.read()
    hands, img = detector.findHands(img)
    img1 = cv2.imread("kisspng-computer-icons-code-coupon-font-computer-coding-5b4cbf4c6bb012.9457556415317563644411.png")

    if len(hands) == 2:
        # print(detector.fingersUp(hands[0]), detector.fingersUp(hands[1]))
        if detector.fingersUp(hands[0]) == [1, 1, 0, 0, 0] and detector.fingersUp(hands[1]) == [1, 1, 0, 0, 0]:
            # print("ZOOMMING GESTUREs")
            lmList1 = hands[0]["lmList"]
            lmList2 = hands[1]["lmList"]

            # Point 8 is teh tip of the finger
            if startDist is None:
                length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)

                startDist = length

            length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)
            scale = int((length - startDist) // 2)
            cx, cy = info[4:]
            # print(scale)
    else:
        startDist = None
    try:
        h1, w1, _ = img1.shape
        newH, newW = ((h1 + scale) // 2) * 2, ((w1 + scale) // 2) * 2
        img1 = cv2.resize(img1, (newW, newH))

        img[cy - newH // 2:cy + newH // 2, cx - newW // 2:cx + newW // 2] = img1

    except:
        pass

    img = cv2.flip(img, 1)
    cv2.imshow("Hollow.os", img)
    cv2.waitKey(1)

当我执行这段代码时,会出现一个名为Unexpected argument的警告

我现在最想要的就是帮助

EN

回答 4

Stack Overflow用户

发布于 2022-02-12 15:04:51

这是因为findhands只返回1个值,而不是2个。

正确的语法是

代码语言:javascript
复制
img2 = detector.findHands(img)
票数 2
EN

Stack Overflow用户

发布于 2022-02-12 16:13:47

原来,我使用了一个1.4.1 cvzone库来使findposition工作,然后我将它改回来了。而且这个很好用

代码语言:javascript
复制
Change your cvzone library version to 1.5.6 so the code will work.

请检查您的cvzone版本,因为如果出现此错误,请将其更改为最新版本,它现在运行良好。

票数 1
EN

Stack Overflow用户

发布于 2022-07-04 17:49:36

cvzone版本需要升级。可以遵循以下步骤,

  1. 检查当前cvzone版本

pip冷冻

  1. 升级版本

安装cvzone -U

就我的情况而言,previous=> cvzone==1.4.1然后成功地卸载了cvzone-1.4.1

成功安装cvzone-1.5.6

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71092717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档