-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpose_detection.py
38 lines (27 loc) · 888 Bytes
/
pose_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2
import mediapipe as mp
# Initialize the MediaPipe Pose model
mp_pose = mp.solutions.pose
mp_drawing = mp.solutions.drawing_utils
pose = mp_pose.Pose()
# Create a video capture object
cap = cv2.VideoCapture("normal.mp4")
# Loop over the video frames
while cap.isOpened():
ret, frame = cap.read()
# Convert the frame to RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Run the MediaPipe Pose model on the image
results = pose.process(image)
# Draw the pose landmarks on the image
if results.pose_landmarks:
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
# Display the image
cv2.imshow('MediaPipe Pose', image)
# Press 'q' to quit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the video capture object
cap.release()
# Destroy all windows
cv2.destroyAllWindows()