Spaces:
Sleeping
Sleeping
| import cv2 | |
| import mediapipe as mp | |
| import numpy as np | |
| import streamlit as st | |
| # Initialize MediaPipe Pose | |
| mp_pose = mp.solutions.pose | |
| pose = mp_pose.Pose(static_image_mode=False, model_complexity=1, enable_segmentation=False, min_detection_confidence=0.5) | |
| mp_drawing = mp.solutions.drawing_utils | |
| # Streamlit web interface | |
| st.title("Yoga Pose Detector") | |
| st.text("Using Mediapipe and Streamlit") | |
| run = st.checkbox('Run') | |
| FRAME_WINDOW = st.image([]) | |
| cap = cv2.VideoCapture(0) | |
| while run: | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| # Convert the BGR image to RGB | |
| image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| # Process the image and detect pose | |
| results = pose.process(image) | |
| # Draw pose landmarks | |
| if results.pose_landmarks: | |
| mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS) | |
| # Convert the image color back for OpenCV | |
| image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) | |
| # Display the image in the web interface | |
| FRAME_WINDOW.image(image) | |
| cap.release() | |
| cv2.destroyAllWindows() | |