Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,19 +8,30 @@ mp_pose = mp.solutions.pose
|
|
| 8 |
pose = mp_pose.Pose(static_image_mode=False, min_detection_confidence=0.5, model_complexity=1)
|
| 9 |
mp_drawing = mp.solutions.drawing_utils
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
frame = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
|
| 13 |
results = pose.process(frame)
|
| 14 |
if results.pose_landmarks:
|
| 15 |
mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
|
|
|
|
|
|
|
| 16 |
return frame
|
| 17 |
|
| 18 |
iface = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
inputs="image",
|
| 21 |
outputs="image",
|
| 22 |
-
title="Live Yoga Pose Detection",
|
| 23 |
-
description="This app detects yoga poses from the live camera feed using MediaPipe.",
|
| 24 |
)
|
| 25 |
|
| 26 |
iface.launch()
|
|
|
|
| 8 |
pose = mp_pose.Pose(static_image_mode=False, min_detection_confidence=0.5, model_complexity=1)
|
| 9 |
mp_drawing = mp.solutions.drawing_utils
|
| 10 |
|
| 11 |
+
# Define a function to classify yoga poses
|
| 12 |
+
def classify_pose(landmarks):
|
| 13 |
+
# Example logic for classifying poses
|
| 14 |
+
if landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].visibility > 0.5 and \
|
| 15 |
+
landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value].visibility > 0.5:
|
| 16 |
+
return "T-Pose"
|
| 17 |
+
# Add more classification rules here
|
| 18 |
+
return "Unknown Pose"
|
| 19 |
+
|
| 20 |
+
def detect_and_classify_pose(input_image):
|
| 21 |
frame = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
|
| 22 |
results = pose.process(frame)
|
| 23 |
if results.pose_landmarks:
|
| 24 |
mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
|
| 25 |
+
pose_classification = classify_pose(results.pose_landmarks.landmark)
|
| 26 |
+
cv2.putText(frame, pose_classification, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
|
| 27 |
return frame
|
| 28 |
|
| 29 |
iface = gr.Interface(
|
| 30 |
+
fn=detect_and_classify_pose,
|
| 31 |
inputs="image",
|
| 32 |
outputs="image",
|
| 33 |
+
title="Live Yoga Pose Detection and Classification",
|
| 34 |
+
description="This app detects and classifies yoga poses from the live camera feed using MediaPipe.",
|
| 35 |
)
|
| 36 |
|
| 37 |
iface.launch()
|