Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import mediapipe as mp
|
| 3 |
+
import numpy as np
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
# Initialize MediaPipe Pose
|
| 7 |
+
mp_pose = mp.solutions.pose
|
| 8 |
+
pose = mp_pose.Pose(static_image_mode=False, model_complexity=1, enable_segmentation=False, min_detection_confidence=0.5)
|
| 9 |
+
mp_drawing = mp.solutions.drawing_utils
|
| 10 |
+
|
| 11 |
+
# Streamlit web interface
|
| 12 |
+
st.title("Yoga Pose Detector")
|
| 13 |
+
st.text("Using Mediapipe and Streamlit")
|
| 14 |
+
|
| 15 |
+
run = st.checkbox('Run')
|
| 16 |
+
FRAME_WINDOW = st.image([])
|
| 17 |
+
|
| 18 |
+
cap = cv2.VideoCapture(0)
|
| 19 |
+
|
| 20 |
+
while run:
|
| 21 |
+
ret, frame = cap.read()
|
| 22 |
+
if not ret:
|
| 23 |
+
break
|
| 24 |
+
|
| 25 |
+
# Convert the BGR image to RGB
|
| 26 |
+
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 27 |
+
|
| 28 |
+
# Process the image and detect pose
|
| 29 |
+
results = pose.process(image)
|
| 30 |
+
|
| 31 |
+
# Draw pose landmarks
|
| 32 |
+
if results.pose_landmarks:
|
| 33 |
+
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
|
| 34 |
+
|
| 35 |
+
# Convert the image color back for OpenCV
|
| 36 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 37 |
+
|
| 38 |
+
# Display the image in the web interface
|
| 39 |
+
FRAME_WINDOW.image(image)
|
| 40 |
+
|
| 41 |
+
cap.release()
|
| 42 |
+
cv2.destroyAllWindows()
|