0

I am writing an opencv project which is a fingers distance finder and making an image(its complicated to explain but I try my best.

When i run the script, I get this error

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

I dont understand this error if someone fix this and answer me I can get the hang off it.

this is the full code

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)

when I do this code there is a warning coming called Unexpected argument

help is mostly what I want now

Miki
  • 40,887
  • 13
  • 123
  • 202
goodcoder
  • 33
  • 3

4 Answers4

2

That's because findhands returns only 1 value, not 2.

The right syntax would be

img2 = detector.findHands(img)
ZygD
  • 22,092
  • 39
  • 79
  • 102
infinity
  • 36
  • 1
1

Turns out I been using a 1.4.1 cvzone library to make the findposition to work then I changed it back. And this works just fine

Change your cvzone library version to 1.5.6 so the code will work.

please check your cvzone version because if this error comes for you then change it to the latest version it works fine now

goodcoder
  • 33
  • 3
1

If we print for example lmList1[8]:

print(lmList1[8]) # It will give us 3 values not 2

In the findDistance:

x1, y1 = p1 # This is wrong
x1, y1, z1 = p # It should be like this
x1, y1, z1 = p1
x2, y2, z2 = p2

Another solution, is you can keep the findDistance as it is and change the line of code into:

length, info, img = detector.findDistance(lmList1[8][:2], lmList2[8][:2], img)

This will take only the first 2 values x1, y1 and x2,y2.

phwt
  • 1,356
  • 1
  • 22
  • 42
0

cvzone version needs to be upgraded. The following steps can be followed,

  1. check the current cvzone version

    pip freeze   
    
  2. Upgrade the version

    pip install cvzone -U 
    

For my case, previous=> cvzone==1.4.1 then Successfully uninstalled cvzone-1.4.1
Successfully installed cvzone-1.5.6

Md.Rakibuz Sultan
  • 759
  • 1
  • 8
  • 13