import cv2 import mediapipe as mp import streamlit as st from PIL import Image import numpy as np # Initialize MediaPipe Pose mp_pose = mp.solutions.pose pose = mp_pose.Pose() mp_drawing = mp.solutions.drawing_utils def process_frame(frame): # Convert the frame to RGB image_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) results = pose.process(image_rgb) if results.pose_landmarks: # Draw the pose annotations on the image mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS) return frame def main(): st.title("Live Pose Detection") st.write("This app uses MediaPipe for real-time pose detection.") # Create a placeholder for the video stream stframe = st.empty() # Open the webcam cap = cv2.VideoCapture(0) while cap.isOpened(): ret, frame = cap.read() if not ret: st.write("Error: Could not read frame.") break # Process the frame frame = process_frame(frame) # Convert the frame to RGB format frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Convert to PIL Image and display stframe.image(Image.fromarray(frame_rgb), channels='RGB', use_column_width=True) cap.release() cv2.destroyAllWindows() if __name__ == "__main__": main()