Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ def paint(frame: np.ndarray) -> np.ndarray:
|
|
| 18 |
if canvas is None:
|
| 19 |
canvas = np.zeros((h, w, 3), dtype=np.uint8)
|
| 20 |
|
|
|
|
| 21 |
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 22 |
results = hands.process(rgb)
|
| 23 |
if results.multi_hand_landmarks:
|
|
@@ -25,12 +26,13 @@ def paint(frame: np.ndarray) -> np.ndarray:
|
|
| 25 |
x, y = int(lm.x * w), int(lm.y * h)
|
| 26 |
cv2.circle(canvas, (x, y), 8, (0, 0, 255), -1)
|
| 27 |
|
|
|
|
| 28 |
return cv2.addWeighted(frame, 0.5, canvas, 0.5, 0)
|
| 29 |
|
| 30 |
demo = gr.Interface(
|
| 31 |
fn=paint,
|
| 32 |
-
inputs=gr.
|
| 33 |
-
outputs=gr.Image(type="numpy"),
|
| 34 |
live=True,
|
| 35 |
title="🖌️ Virtual Painter",
|
| 36 |
description="Move your index finger in front of the camera to draw!"
|
|
|
|
| 18 |
if canvas is None:
|
| 19 |
canvas = np.zeros((h, w, 3), dtype=np.uint8)
|
| 20 |
|
| 21 |
+
# MediaPipe expects RGB
|
| 22 |
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 23 |
results = hands.process(rgb)
|
| 24 |
if results.multi_hand_landmarks:
|
|
|
|
| 26 |
x, y = int(lm.x * w), int(lm.y * h)
|
| 27 |
cv2.circle(canvas, (x, y), 8, (0, 0, 255), -1)
|
| 28 |
|
| 29 |
+
# Blend live frame and canvas
|
| 30 |
return cv2.addWeighted(frame, 0.5, canvas, 0.5, 0)
|
| 31 |
|
| 32 |
demo = gr.Interface(
|
| 33 |
fn=paint,
|
| 34 |
+
inputs=gr.inputs.Image(source="webcam", type="numpy"),
|
| 35 |
+
outputs=gr.outputs.Image(type="numpy"),
|
| 36 |
live=True,
|
| 37 |
title="🖌️ Virtual Painter",
|
| 38 |
description="Move your index finger in front of the camera to draw!"
|