|
|
import cv2 |
|
|
import mediapipe as mp |
|
|
import streamlit as st |
|
|
from PIL import Image |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
mp_pose = mp.solutions.pose |
|
|
pose = mp_pose.Pose() |
|
|
mp_drawing = mp.solutions.drawing_utils |
|
|
|
|
|
def process_frame(frame): |
|
|
|
|
|
image_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
|
results = pose.process(image_rgb) |
|
|
if results.pose_landmarks: |
|
|
|
|
|
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.") |
|
|
|
|
|
|
|
|
stframe = st.empty() |
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(0) |
|
|
|
|
|
while cap.isOpened(): |
|
|
ret, frame = cap.read() |
|
|
if not ret: |
|
|
st.write("Error: Could not read frame.") |
|
|
break |
|
|
|
|
|
|
|
|
frame = process_frame(frame) |
|
|
|
|
|
|
|
|
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
|
|
|
|
stframe.image(Image.fromarray(frame_rgb), channels='RGB', use_column_width=True) |
|
|
|
|
|
cap.release() |
|
|
cv2.destroyAllWindows() |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |