#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Aug 4 14:49:57 2024 @author: ysnrfd """ import cv2 import mediapipe as mp # Initialize MediaPipe Pose module mp_pose = mp.solutions.pose pose = mp_pose.Pose() # Initialize MediaPipe Drawing module mp_drawing = mp.solutions.drawing_utils # Initialize webcam cap = cv2.VideoCapture(0) while True: # Read frame from webcam ret, frame = cap.read() if not ret: break # Convert the frame to RGB frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Process the frame and get pose landmarks results = pose.process(frame_rgb) # Draw pose landmarks on the frame if results.pose_landmarks: mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS) # Display the resulting frame cv2.imshow("Pose Detection", frame) # Exit on 'q' key press if cv2.waitKey(1) & 0xFF == ord('q'): break # Release resources cap.release() cv2.destroyAllWindows()