Piarasingh85 commited on
Commit
b7440b9
·
verified ·
1 Parent(s): a783f57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -38
app.py CHANGED
@@ -1,44 +1,35 @@
 
 
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
- st.error("Failed to capture image from webcam")
24
- break
25
-
26
- # Convert the BGR image to RGB
27
- image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
28
-
29
- # Process the image and detect pose
30
- results = pose.process(image)
31
-
32
- # Draw pose landmarks
33
- if results.pose_landmarks:
34
- mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
35
-
36
- # Convert the image color back for OpenCV
37
- image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
38
-
39
- # Display the image in the web interface
40
- FRAME_WINDOW.image(image)
41
-
42
- cap.release()
43
- cv2.destroyAllWindows()
44
-
 
1
+ import gradio as gr
2
+ import math
3
  import cv2
 
4
  import numpy as np
5
+ import mediapipe as mp
6
 
7
+ # Initialize mediapipe pose class
8
  mp_pose = mp.solutions.pose
9
+ pose = mp_pose.Pose(static_image_mode=False, min_detection_confidence=0.5, model_complexity=1)
10
  mp_drawing = mp.solutions.drawing_utils
11
 
12
+ def detectPose(image):
13
+ # Your detectPose function implementation
14
+ pass
15
+
16
+ def classifyPose(landmarks, image):
17
+ # Your classifyPose function implementation
18
+ pass
19
+
20
+ def detect_yoga_poses(frame):
21
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
22
+ frame, landmarks = detectPose(frame)
23
+ if landmarks:
24
+ frame, _ = classifyPose(landmarks, frame)
25
+ return frame
26
+
27
+ iface = gr.Interface(
28
+ fn=detect_yoga_poses,
29
+ inputs="webcam",
30
+ outputs="image",
31
+ title="Live Yoga Pose Detection",
32
+ description="This app detects yoga poses from the live camera feed using MediaPipe.",
33
+ )
34
+
35
+ iface.launch()