-2

I am trying to zoom into a picture with usage of two hands (gesture controled image zoom), but when trying to use two hands I get this error but I don't know why. When making my program I followed this tutorial: https://www.youtube.com/watch?v=VPaFV3QBsEw&t=675s. It's strange because the program worked for him.

This is the error I get:

  hands, img = detector.findHands(img)

ValueError: too many values to unpack (expected 2)

This is my code:

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)
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Try `print(detector.findHands(img))` and `len(detector.findHands(img))`, what output do you see? – kinshukdua Oct 16 '21 at 09:13
  • The source code of the `findHands` method is [here](https://github.com/cvzone/cvzone/blob/master/cvzone/HandTrackingModule.py#L40). And it should indeed return two items back. Do what kinskukdua suggested and check to see if your version of the library is older with `cvzone.__version__`. Also use `help(detector.findHands)` to see its documentation to see its argument signature and what it returns. – Reti43 Oct 16 '21 at 09:20
  • when i used len(detector.findHands(img)) the output was 480 – gasper_thebeast101 Oct 16 '21 at 15:30
  • and the version I am using is cvzone==1.4.1, because newest versions don't have HandTrackingModule option which I need for easyer making of other projects – gasper_thebeast101 Oct 16 '21 at 15:32

1 Answers1

1

cvzone library keeps updating their library every time. As you can see at the beginning of the video, when he imports the cvzone package he uses cvzone version 1.5.0.

I tried your code with other versions and got an error similar to yours but with version 1.5.0 your code worked great.

you can use my answer here to change the version of your cvzone library in your project to 1.5.0.

Roy Amoyal
  • 717
  • 4
  • 14
  • I am using version 1.4.1 because I need it for other projects. Because they removed HandTrackingModule option from 1.5.0, are there any chances so that my code vould work for my version? – gasper_thebeast101 Oct 16 '21 at 15:22
  • no, you will have to separate the functions from the original code of cvzone to 2 different methods.. – Roy Amoyal Oct 17 '21 at 10:14