Spaces:
Runtime error
Runtime error
Add a basic demo of hand & finger tracking
Browse files- README.md +2 -2
- app.py +40 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: streamlit
|
|
|
1 |
---
|
2 |
+
title: Hand & Finger Tracking w/ MediaPipe
|
3 |
+
emoji: π
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: streamlit
|
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_webrtc import webrtc_streamer
|
3 |
+
import av
|
4 |
+
import mediapipe as mp
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
mp_hands = mp.solutions.hands
|
8 |
+
mp_hands_connections = mp.solutions.hands_connections
|
9 |
+
hands = mp_hands.Hands()
|
10 |
+
mp_draw = mp.solutions.drawing_utils
|
11 |
+
|
12 |
+
connections = {
|
13 |
+
'HAND_CONNECTIONS': mp_hands_connections.HAND_CONNECTIONS,
|
14 |
+
'HAND_PALM_CONNECTIONS': mp_hands_connections.HAND_PALM_CONNECTIONS,
|
15 |
+
'HAND_THUMB_CONNECTIONS': mp_hands_connections.HAND_THUMB_CONNECTIONS,
|
16 |
+
'HAND_INDEX_FINGER_CONNECTIONS': mp_hands_connections.HAND_INDEX_FINGER_CONNECTIONS,
|
17 |
+
'HAND_MIDDLE_FINGER_CONNECTIONS': mp_hands_connections.HAND_MIDDLE_FINGER_CONNECTIONS,
|
18 |
+
'HAND_RING_FINGER_CONNECTIONS': mp_hands_connections.HAND_RING_FINGER_CONNECTIONS,
|
19 |
+
'HAND_PINKY_FINGER_CONNECTIONS': mp_hands_connections.HAND_PINKY_FINGER_CONNECTIONS,
|
20 |
+
}
|
21 |
+
|
22 |
+
draw_background = st.checkbox("Draw background", value=True)
|
23 |
+
selected_connection = st.selectbox("Select connections to draw", list(connections.keys()))
|
24 |
+
|
25 |
+
def process_hands(frame):
|
26 |
+
img = frame.to_ndarray(format="bgr24")
|
27 |
+
results = hands.process(img)
|
28 |
+
output_img = img if draw_background else np.zeros_like(img)
|
29 |
+
if results.multi_hand_landmarks:
|
30 |
+
for hand_landmarks in results.multi_hand_landmarks:
|
31 |
+
mp_draw.draw_landmarks(output_img, hand_landmarks, connections[selected_connection])
|
32 |
+
return av.VideoFrame.from_ndarray(output_img, format="bgr24")
|
33 |
+
|
34 |
+
webrtc_streamer(
|
35 |
+
key="streamer",
|
36 |
+
video_frame_callback=process_hands,
|
37 |
+
media_stream_constraints={"video": True, "audio": False},
|
38 |
+
)
|
39 |
+
|
40 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
mediapipe
|
2 |
+
streamlit-webrtc
|
3 |
+
cv2
|