首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python,cvzone -为什么我会得到这个ValueError?

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

Stack Overflow用户
提问于 2021-10-16 09:08:52
回答 1查看 347关注 0票数 -1

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

这是我得到的错误:

代码语言:javascript
复制
  hands, img = detector.findHands(img)

ValueError: too many values to unpack (expected 2)

这是我的代码:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-16 11:24:33

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

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

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

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

https://stackoverflow.com/questions/69594197

复制
相关文章

相似问题

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