google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://mediapipe.dev
Apache License 2.0
26.8k stars 5.09k forks source link

Creating a new HAND_CONNECTIONS in python #1280

Closed Borzborz closed 3 years ago

Borzborz commented 3 years ago

Hello, I wanted to create a new hand connection frozenset in hands.py like so:

HAND_TIP_CONNECTIONS = frozenset([
    (HandLandmark.THUMB_TIP,HandLandmark.INDEX_FINGER_TIP),
    (HandLandmark.INDEX_FINGER_TIP,HandLandmark.MIDDLE_FINGER_TIP),
    (HandLandmark.MIDDLE_FINGER_TIP,HandLandmark.RING_FINGER_TIP),
    (HandLandmark.RING_FINGER_TIP,HandLandmark.PINKY_TIP),
    (HandLandmark.PINKY_TIP,HandLandmark.WRIST),
    (HandLandmark.WRIST,HandLandmark.THUMB_TIP)
    ])

I wanted to do this so I can connect the tips of the fingers along with the wrist landmark when I use draw_landmarks. However, when I save the change to hands.py and try to call draw_landmarks in my code like so : mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_TIP_CONNECTIONS) my code get an error saying

File "handGesture.py", line 49, in <module>
    mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_TIP_CONNECTIONS)
AttributeError: module 'mediapipe.python.solutions.hands' has no attribute 'HAND_TIP_CONNECTIONS'

I'm not sure what to do here. Any suggestions on how I can create a new connection would be much appreciated.

jiuqiant commented 3 years ago

If you modify the source code, you probably need to rerun the setup workflow to generate the package?

In fact, instead of touching hands.py, you can define HAND_TIP_CONNECTIONS in your python code and pass it to draw_landmarks().

Borzborz commented 3 years ago

Oh, nice! thank you.