cvzone / cvzone

This is a Computer vision package that makes its easy to run Image processing and AI functions. At the core it uses OpenCV and Mediapipe libraries.
MIT License
1.14k stars 256 forks source link

'cvzone' has no attribute 'HandDetector' #21

Open its-Yogesh opened 2 years ago

its-Yogesh commented 2 years ago

I tried to run the below mentioned Example code. but I got an Attribute error saying

AttributeError: module 'cvzone' has no attribute 'HandDetector'.

Help me to resolve this issue.

the Example code is.

import cvzone
import cv2

cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
detector = cvzone.HandDetector(detectionCon=0.5, maxHands=1)

while True:
    # Get image frame
    success, img = cap.read()

    # Find the hand and its landmarks
    img = detector.findHands(img)
    lmList, bbox = detector.findPosition(img)

    # Display
    cv2.imshow("Image", img)
    cv2.waitKey(1)
jonetwo commented 2 years ago

me too

francoisschwarzentruber commented 2 years ago

Hello! Maybe try from cvzone.HandTrackingModule import HandDetector and do detector = HandDetector(detectionCon=0.0, maxHands=1)

its-Yogesh commented 2 years ago

Thanks for you Advice but still it shows the same error.

On Fri, 26 Nov 2021, 7:00 pm François Schwarzentruber, < @.***> wrote:

Hello! Maybe try from cvzone.HandTrackingModule import HandDetector and do detector = HandDetector(detectionCon=0.0, maxHands=1)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cvzone/cvzone/issues/21#issuecomment-979979893, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARISI7J3QI2YA4M3H7VJOITUN6DW5ANCNFSM5IP7SLYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Giovannibriglia commented 2 years ago

I have the same error

fancymask01 commented 2 years ago

Make sure mediapipe is installed. Try: import cv2 from cvzone.HandTrackingModule import HandDetector

cap = cv2.VideoCapture(0) cap.set(3, 1280) cap.set(4, 720) detector = HandDetector(detectionCon=0.8, maxHands=1)

Mandizvidzafn commented 2 years ago

Hey its-Yogesh, what francoisschwarxentruber said is right. Try this:

from cvzone.HandTrackingModule import HandDetector import cv2

cap = cv2.VideoCapture(0) detector = HandDetector(detectionCon=0.8, maxHands=2) while True:

Get image frame

success, img = cap.read()
# Find the hand and its landmarks
hands, img = detector.findHands(img)  # with draw
#hands = detector.findHands(img, draw=False)  # without draw

if hands:
    # Hand 1
    hand1 = hands[0]
    lmList1 = hand1["lmList"]  # List of 21 Landmark points
    bbox1 = hand1["bbox"]  # Bounding box info x,y,w,h
    centerPoint1 = hand1['center']  # center of the hand cx,cy
    handType1 = hand1["type"]  # Handtype Left or Right

    fingers1 = detector.fingersUp(hand1)

    if len(hands) == 2:
        # Hand 2
        hand2 = hands[1]
        lmList2 = hand2["lmList"]  # List of 21 Landmark points
        bbox2 = hand2["bbox"]  # Bounding box info x,y,w,h
        centerPoint2 = hand2['center']  # center of the hand cx,cy
        handType2 = hand2["type"]  # Hand Type "Left" or "Right"

        fingers2 = detector.fingersUp(hand2)

        # Find Distance between two Landmarks. Could be same hand or different hands
        length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)  # with draw
        # length, info = detector.findDistance(lmList1[8], lmList2[8])  # with draw
# Display
cv2.imshow("Image", img)
if cv2.waitKey(1) == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

alikhorshidi commented 2 years ago

Thanks! @Mandizvidzafn But when I set maxHands to 2, It gives me an Error!

INFO: Created TensorFlow Lite XNNPACK delegate for CPU. Traceback (most recent call last): File "/home/alikhorshidi/PycharmProjects/GestureRobotArmControl/GestureControlArm.py", line 34, in length, info, img = detector.findDistance(lmList1[8], lmList2[8], img) # with draw File "/home/alikhorshidi/PycharmProjects/GestureRobotArmControl/venv/lib/python3.9/site-packages/cvzone/HandTrackingModule.py", line 143, in findDistance x1, y1 = p1 ValueError: too many values to unpack (expected 2)

alikhorshidi commented 2 years ago

It works thanks to @Mandizvidzafn

from cvzone.HandTrackingModule import HandDetector
import cv2

cap = cv2.VideoCapture(0)
detector = HandDetector(detectionCon=0.8, maxHands=1)
while True:

# Get image frame
    success, img = cap.read()
# Find the hand and its landmarks
    hands, img = detector.findHands(img) # with draw
#hands = detector.findHands(img, draw=False) # without draw
    if hands:
        # Hand 1
        hand1 = hands[0]
        lmList1 = hand1["lmList"]  # List of 21 Landmark points
        bbox1 = hand1["bbox"]  # Bounding box info x,y,w,h
        centerPoint1 = hand1['center']  # center of the hand cx,cy
        handType1 = hand1["type"]  # Handtype Left or Right

        fingers1 = detector.fingersUp(hand1)

        if len(hands) == 2:
            # Hand 2
            hand2 = hands[1]
            lmList2 = hand2["lmList"]  # List of 21 Landmark points
            bbox2 = hand2["bbox"]  # Bounding box info x,y,w,h
            centerPoint2 = hand2['center']  # center of the hand cx,cy
            handType2 = hand2["type"]  # Hand Type "Left" or "Right"

            fingers2 = detector.fingersUp(hand2)

            # Find Distance between two Landmarks. Could be same hand or different hands
            length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)  # with draw
            # length, info = detector.findDistance(lmList1[8], lmList2[8])  # with draw
    # Display
    cv2.imshow("Image", img)
    if cv2.waitKey(1) == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
BarotbekTurxonov commented 2 years ago

hi everyone i.m getting this problem
hands, img = detector.findHands(img, draw=True) ValueError: too many values to unpack (expected 2)

BarotbekTurxonov commented 2 years ago

ishlab chiqarish misol kodini ishga tushirishga harakat qildim. lekin menda Atribut xatosi bor

use 1.4.1 version of cvzone

AttributeError: "cvzone" modulida "HandDetector" atributi yo'q.

Bu muammoni hal qilishimga yordam bering.

misol kodi.

import cvzone
import cv2

cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
detector = cvzone.HandDetector(detectionCon=0.5, maxHands=1)

while True:
    # Get image frame
    success, img = cap.read()

    # Find the hand and its landmarks
    img = detector.findHands(img)
    lmList, bbox = detector.findPosition(img)

    # Display
    cv2.imshow("Image", img)
    cv2.waitKey(1)
Pixie34 commented 1 year ago

i can´t get the distance between 2 landmarks to show, any help?

from cvzone.HandTrackingModule import HandDetector import cv2

cap = cv2.VideoCapture(0) detector = HandDetector(detectionCon=0.5, maxHands= 1)

while True:

hacer un cuadro

success, img = cap.read()

detectar las manos y trazar las rayitas

hands, img = detector.findHands(img) # with draw

if hands:
    # Mano 1
    hand1 = hands[0]
    lmList1 = hand1["lmList"]  # List of 21 Landmark points
    bbox1 = hand1["bbox"]  # Bounding box info x,y,w,h
    centerPoint1 = hand1['center']  # center of the hand cx,cy
    handType1 = hand1["type"]  # Handtype Left or Right

    fingers1 = detector.fingersUp(hand1)

if len(hands) == 2:
    # Mano 2
    hand2 = hands[1]
    lmList2 = hand2["lmList"]  # List of 21 Landmark points
    bbox2 = hand2["bbox"]  # Bounding box info x,y,w,h
    centerPoint2 = hand2['center']  # center of the hand cx,cy
    handType2 = hand2["type"]  # Hand Type "Left" or "Right"

    fingers2 = detector.fingersUp(hand2)

    # Distancia entre 2 Landmarks. puede ser de la misma mano OJOOOOOO
    length, info, img = detector.findDistance(lmList2[4], lmList2[12], img)  # with draw
        # length, info = detector.findDistance(lmList1[8], lmList2[8])  # with draw

# Display
cv2.imshow("Image", img)
if cv2.waitKey(1) == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

Tiran-Jayasekara commented 1 year ago

Can we use mediapipe , cvzone for mobile aplication?

jonetwo commented 1 year ago

probably can't

@.***

@.*** |

---- Replied Message ---- | From | Tiran @.> | | Date | 12/25/2022 01:43 | | To | @.> | | Cc | @.>@.> | | Subject | Re: [cvzone/cvzone] 'cvzone' has no attribute 'HandDetector' (Issue #21) |

Can we use mediapipe , cvzone for mobile aplication?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

BarotbekTurxonov commented 1 year ago

Of cource no!

ErandiJayaweera commented 1 year ago

from cvzone.HandTrackingModule import HandDetector put this line when your import/calling your libraries. then check if it works. this worked for me

jonetwo commented 1 year ago

Mine could work, check wether have you downloaded the mediapipe, or you can change a version of cvzone. Wish you the best.

@.***

@.*** |

---- Replied Message ---- | From | @.> | | Date | 08/23/2023 08:14 | | To | @.> | | Cc | @.>@.> | | Subject | Re: [cvzone/cvzone] 'cvzone' has no attribute 'HandDetector' (Issue #21) |

from cvzone.HandTrackingModule import HandDetector put this line when your import/calling your libraries. then check if it works. this worked for me

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

vijaycse2003 commented 1 year ago

cvzone version 1.5.6

from cvzone.HandTrackingModule import HandDetector

detector=HandDetector(detectionCon=0.8, maxHands=2)

error: Invoked:0.8 something error occur

shivam-17 commented 4 months ago

Hey its-Yogesh, what francoisschwarxentruber said is right. Try this:

from cvzone.HandTrackingModule import HandDetector import cv2

cap = cv2.VideoCapture(0) detector = HandDetector(detectionCon=0.8, maxHands=2) while True: # Get image frame success, img = cap.read() # Find the hand and its landmarks hands, img = detector.findHands(img) # with draw #hands = detector.findHands(img, draw=False) # without draw

if hands:
    # Hand 1
    hand1 = hands[0]
    lmList1 = hand1["lmList"]  # List of 21 Landmark points
    bbox1 = hand1["bbox"]  # Bounding box info x,y,w,h
    centerPoint1 = hand1['center']  # center of the hand cx,cy
    handType1 = hand1["type"]  # Handtype Left or Right

    fingers1 = detector.fingersUp(hand1)

    if len(hands) == 2:
        # Hand 2
        hand2 = hands[1]
        lmList2 = hand2["lmList"]  # List of 21 Landmark points
        bbox2 = hand2["bbox"]  # Bounding box info x,y,w,h
        centerPoint2 = hand2['center']  # center of the hand cx,cy
        handType2 = hand2["type"]  # Hand Type "Left" or "Right"

        fingers2 = detector.fingersUp(hand2)

        # Find Distance between two Landmarks. Could be same hand or different hands
        length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)  # with draw
        # length, info = detector.findDistance(lmList1[8], lmList2[8])  # with draw
# Display
cv2.imshow("Image", img)
if cv2.waitKey(1) == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

There's a small modification, since while calculating it accepts 3 values hence the updated code should be:

from cvzone.HandTrackingModule import HandDetector
import cv2

cap = cv2.VideoCapture(0)
detector = HandDetector(detectionCon=0.8, maxHands=1)
while True:

# Get image frame
    success, img = cap.read()
# Find the hand and its landmarks
    hands, img = detector.findHands(img) # with draw
#hands = detector.findHands(img, draw=False) # without draw
    if hands:
        # Hand 1
        hand1 = hands[0]
        lmList1 = hand1["lmList"]  # List of 21 Landmark points
        bbox1 = hand1["bbox"]  # Bounding box info x,y,w,h
        centerPoint1 = hand1['center']  # center of the hand cx,cy
        handType1 = hand1["type"]  # Handtype Left or Right

        fingers1 = detector.fingersUp(hand1)

        if len(hands) == 2:
            # Hand 2
            hand2 = hands[1]
            lmList2 = hand2["lmList"]  # List of 21 Landmark points
            bbox2 = hand2["bbox"]  # Bounding box info x,y,w,h
            centerPoint2 = hand2['center']  # center of the hand cx,cy
            handType2 = hand2["type"]  # Hand Type "Left" or "Right"

            fingers2 = detector.fingersUp(hand2)

            # Find Distance between two Landmarks. Could be same hand or different hands
            # Now you see that in findDistance, x1,y1 = p1 , this will give you error since x1, y1, z1 = p # It should be like this
             length, info, img = detector.findDistance(lmList1[8][:2], lmList2[8][:2], img)
            # length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)  # with draw
            # length, info = detector.findDistance(lmList1[8], lmList2[8])  # with draw
    # Display
    cv2.imshow("Image", img)
    if cv2.waitKey(1) == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()