当前位置:首页 > 教育 > 正文

Python,cvzone -为什么我会得到这个ValueError?

提问开始:

我试图用两只手(手势控制图像缩放)放大一张图片,但当我试图用两只手时,我得到了这个错误,但我不知道为什么。在编写我的程序时,我遵循以下教程:https://www.youtube.com/watch?v=VPaFV3QBsEw&t=675s。这很奇怪,因为这个程序对他有效。

这是我得到的错误:

  hands, img = detector.findHands(img)

ValueError: too many values to unpack (expected 2)

这是我的代码:

import cv2
from cvzone.HandTrackingModule import HandDetector
 
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
 
detector = HandDetector(detectionCon=0.7)
startDist = None
scale = 0
cx, cy = 500,500

while True:
    success, img = cap.read()
    hands, img = detector.findHands(img)
    img1 = cv2.imread("kung_fu_panda.png")
 
    if len(hands) == 2:
        
        if detector.fingersUp(hands[0]) == [1, 1, 0, 0, 0] and \
                detector.fingersUp(hands[1]) == [1, 1, 0, 0, 0]:
         
            lmList1 = hands[0]["lmList"]
            lmList2 = hands[1]["lmList"]
            # point 8 is the tip of the index finger
            if startDist is None:
                length, info, img = detector.findDistance(hands[0]["center"], hands[1]["center"], img)
                startDist = length
 
            length, info, img = detector.findDistance(hands[0]["center"], hands[1]["center"], 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
 
    cv2.imshow("Image", img)
    cv2.waitKey(1)
回答开始:得票数 1

cvzone库每次都会更新它们的库。正如您在视频开头所看到的,当他导入cvzone包时,他使用的是cvzone版本1.5.0。

我在其他版本中尝试了你的代码,得到了一个与你的类似的错误,但在1.5.0版本中,你的代码工作得很好。

您可以使用my answer here将项目中的cvzone库版本更改为1.5.0。

总结

以上是真正的电脑专家为你收集整理的Python,cvzone -为什么我会得到这个ValueError?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得真正的电脑专家网站内容还不错,欢迎将真正的电脑专家推荐给好友。

有话要说...

取消
扫码支持 支付码