Spaces:
Runtime error
Runtime error
Add options to upload an image or take a picture
Browse files
app.py
CHANGED
|
@@ -20,7 +20,8 @@ connections = {
|
|
| 20 |
'HAND_PINKY_FINGER_CONNECTIONS': mp_hands_connections.HAND_PINKY_FINGER_CONNECTIONS,
|
| 21 |
}
|
| 22 |
|
| 23 |
-
def
|
|
|
|
| 24 |
results = hands.process(img)
|
| 25 |
output_img = img if draw_background else np.zeros_like(img)
|
| 26 |
if results.multi_hand_landmarks:
|
|
@@ -36,7 +37,7 @@ def process_video(video_path, selected_connection, draw_background):
|
|
| 36 |
with media.VideoWriter(
|
| 37 |
out_path, shape=r.shape, fps=r.fps, bps=r.bps) as w:
|
| 38 |
for image in r:
|
| 39 |
-
w.add_image(
|
| 40 |
return out_path
|
| 41 |
|
| 42 |
|
|
@@ -58,6 +59,12 @@ with demo:
|
|
| 58 |
value=connection_keys[0],
|
| 59 |
)
|
| 60 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
with gr.TabItem(label="Record a video"):
|
| 62 |
recorded_video = gr.Video(source="webcam", format="mp4")
|
| 63 |
submit_recorded_video = gr.Button(value="Process Video")
|
|
@@ -67,8 +74,11 @@ with demo:
|
|
| 67 |
|
| 68 |
with gr.Column():
|
| 69 |
processed_video = gr.Video()
|
|
|
|
| 70 |
|
| 71 |
gr.Markdown('<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=kristyc.mediapipe-hands" />')
|
|
|
|
|
|
|
| 72 |
submit_recorded_video.click(fn=process_video, inputs=[recorded_video, selected_connection, draw_background], outputs=[processed_video])
|
| 73 |
submit_uploaded_video.click(fn=process_video, inputs=[recorded_video, selected_connection, draw_background], outputs=[processed_video])
|
| 74 |
|
|
|
|
| 20 |
'HAND_PINKY_FINGER_CONNECTIONS': mp_hands_connections.HAND_PINKY_FINGER_CONNECTIONS,
|
| 21 |
}
|
| 22 |
|
| 23 |
+
def process_image(img, selected_connection, draw_background):
|
| 24 |
+
print(img)
|
| 25 |
results = hands.process(img)
|
| 26 |
output_img = img if draw_background else np.zeros_like(img)
|
| 27 |
if results.multi_hand_landmarks:
|
|
|
|
| 37 |
with media.VideoWriter(
|
| 38 |
out_path, shape=r.shape, fps=r.fps, bps=r.bps) as w:
|
| 39 |
for image in r:
|
| 40 |
+
w.add_image(process_image(image, selected_connection, draw_background))
|
| 41 |
return out_path
|
| 42 |
|
| 43 |
|
|
|
|
| 59 |
value=connection_keys[0],
|
| 60 |
)
|
| 61 |
with gr.Tabs():
|
| 62 |
+
with gr.TabItem(label="Upload an image"):
|
| 63 |
+
uploaded_image = gr.Image(type="numpy")
|
| 64 |
+
submit_uploaded_image = gr.Button(value="Process Image")
|
| 65 |
+
with gr.TabItem(label="Take a picture"):
|
| 66 |
+
camera_picture = gr.Image(source="webcam", type="numpy")
|
| 67 |
+
submit_camera_picture = gr.Button(value="Process Image")
|
| 68 |
with gr.TabItem(label="Record a video"):
|
| 69 |
recorded_video = gr.Video(source="webcam", format="mp4")
|
| 70 |
submit_recorded_video = gr.Button(value="Process Video")
|
|
|
|
| 74 |
|
| 75 |
with gr.Column():
|
| 76 |
processed_video = gr.Video()
|
| 77 |
+
processed_image = gr.Image()
|
| 78 |
|
| 79 |
gr.Markdown('<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=kristyc.mediapipe-hands" />')
|
| 80 |
+
submit_uploaded_image.click(fn=process_image, inputs=[uploaded_image, selected_connection, draw_background], outputs=[processed_image])
|
| 81 |
+
submit_camera_picture.click(fn=process_image, inputs=[camera_picture, selected_connection, draw_background], outputs=[processed_image])
|
| 82 |
submit_recorded_video.click(fn=process_video, inputs=[recorded_video, selected_connection, draw_background], outputs=[processed_video])
|
| 83 |
submit_uploaded_video.click(fn=process_video, inputs=[recorded_video, selected_connection, draw_background], outputs=[processed_video])
|
| 84 |
|