-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmediaPipe.py
More file actions
44 lines (35 loc) · 1.32 KB
/
mediaPipe.py
File metadata and controls
44 lines (35 loc) · 1.32 KB
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
39
40
41
42
43
44
import mediapipe as mp
import cv2
# Calling the pose solution from MediaPipe
mp_pose = mp.solutions.pose
# Calling the solution for image drawing from MediaPipe
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
# Opening the webcam
cap = cv2.VideoCapture(0)
# Calling the pose detection model
with mp_pose.Pose(
min_detection_confidence=0.5,
min_tracking_confidence=0.5) as pose:
# Looping through the webcam frames
while cap.isOpened():
# Reading the webcam frame
success, image = cap.read()
if success:
# Managing the webcam frame
image.flags.writeable = False
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Detecting the pose with the image
results = pose.process(image)
# Drawing the pose detection results
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
mp_drawing.draw_landmarks(
image,
results.pose_landmarks,
mp_pose.POSE_CONNECTIONS,
landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style())
cv2.imshow('MediaPipe Pose', cv2.flip(image, 1))
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()