upgraded code based on newer gradio version
Browse files
app.py
CHANGED
|
@@ -1,43 +1,47 @@
|
|
| 1 |
import cv2
|
| 2 |
import gradio as gr
|
| 3 |
import mediapipe as mp
|
|
|
|
| 4 |
mp_drawing = mp.solutions.drawing_utils
|
| 5 |
mp_drawing_styles = mp.solutions.drawing_styles
|
| 6 |
mp_hands = mp.solutions.hands
|
| 7 |
|
| 8 |
def fun(img):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
with gr.Column():
|
| 31 |
-
input = gr.Webcam(streaming=True)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
inputs = input,
|
| 39 |
-
outputs = output)
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
demo.launch(debug=True)
|
|
|
|
| 1 |
import cv2
|
| 2 |
import gradio as gr
|
| 3 |
import mediapipe as mp
|
| 4 |
+
|
| 5 |
mp_drawing = mp.solutions.drawing_utils
|
| 6 |
mp_drawing_styles = mp.solutions.drawing_styles
|
| 7 |
mp_hands = mp.solutions.hands
|
| 8 |
|
| 9 |
def fun(img):
|
| 10 |
+
print(type(img))
|
| 11 |
+
with mp_hands.Hands(
|
| 12 |
+
model_complexity=0,
|
| 13 |
+
min_detection_confidence=0.5,
|
| 14 |
+
min_tracking_confidence=0.5
|
| 15 |
+
) as hands:
|
| 16 |
+
img.flags.writeable = False
|
| 17 |
+
image = cv2.flip(img[:, :, ::-1], 1)
|
| 18 |
+
# Convert the BGR image to RGB before processing.
|
| 19 |
+
results = hands.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
|
| 20 |
+
image.flags.writeable = True
|
| 21 |
+
if results.multi_hand_landmarks:
|
| 22 |
+
for hand_landmarks in results.multi_hand_landmarks:
|
| 23 |
+
mp_drawing.draw_landmarks(
|
| 24 |
+
image,
|
| 25 |
+
hand_landmarks,
|
| 26 |
+
mp_hands.HAND_CONNECTIONS,
|
| 27 |
+
mp_drawing_styles.get_default_hand_landmarks_style(),
|
| 28 |
+
mp_drawing_styles.get_default_hand_connections_style()
|
| 29 |
+
)
|
| 30 |
|
| 31 |
+
return cv2.flip(image[:, :, ::-1], 1)
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
with gr.Blocks(title="Realtime Keypoint Detection | Data Science Dojo", css="footer {display:none !important} .output-markdown{display:none !important}") as demo:
|
| 34 |
+
with gr.Row():
|
| 35 |
+
with gr.Column():
|
| 36 |
+
webcam_input = gr.Video(source="webcam", label="Webcam Input")
|
| 37 |
|
| 38 |
+
with gr.Column():
|
| 39 |
+
output = gr.Image(label="Output Image")
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
webcam_input.stream(
|
| 42 |
+
fn=fun,
|
| 43 |
+
inputs=webcam_input,
|
| 44 |
+
outputs=output
|
| 45 |
+
)
|
| 46 |
|
| 47 |
demo.launch(debug=True)
|