AmirKaseb commited on
Commit
7315d60
·
verified ·
1 Parent(s): 3e6692f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import mediapipe as mp
3
+ import streamlit as st
4
+ from PIL import Image
5
+ import numpy as np
6
+
7
+ # Initialize MediaPipe Pose
8
+ mp_pose = mp.solutions.pose
9
+ pose = mp_pose.Pose()
10
+ mp_drawing = mp.solutions.drawing_utils
11
+
12
+ def process_frame(frame):
13
+ # Convert the frame to RGB
14
+ image_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
15
+ results = pose.process(image_rgb)
16
+ if results.pose_landmarks:
17
+ # Draw the pose annotations on the image
18
+ mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
19
+ return frame
20
+
21
+ def main():
22
+ st.title("Live Pose Detection")
23
+ st.write("This app uses MediaPipe for real-time pose detection.")
24
+
25
+ # Create a placeholder for the video stream
26
+ stframe = st.empty()
27
+
28
+ # Open the webcam
29
+ cap = cv2.VideoCapture(0)
30
+
31
+ while cap.isOpened():
32
+ ret, frame = cap.read()
33
+ if not ret:
34
+ st.write("Error: Could not read frame.")
35
+ break
36
+
37
+ # Process the frame
38
+ frame = process_frame(frame)
39
+
40
+ # Convert the frame to RGB format
41
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
42
+ # Convert to PIL Image and display
43
+ stframe.image(Image.fromarray(frame_rgb), channels='RGB', use_column_width=True)
44
+
45
+ cap.release()
46
+ cv2.destroyAllWindows()
47
+
48
+ if __name__ == "__main__":
49
+ main()