-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpose_detection.py
50 lines (36 loc) · 1.52 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
#########################################################
#!pip install mediapipe
#########################################################
# step 1: Import all necessary libraries
import cv2
import mediapipe as mp
#########################################################
# step 2: Identify webcam
cap = cv2.VideoCapture(0)
#########################################################
# leveraging the mediapipe Library used for Pose detection
mpPose = mp.solutions.pose
pose = mpPose.Pose()
# pose = mpPose.pose(static_image_mode = False, upper body only = False, smooth Landmark =True, min_detection_confidence = 0.5)
#########################################################
# To draw and connect the landmarks
mpDraw = mp.solutions.drawing_utils
#########################################################
# switch on your cam
while True:
_, img = cap.read()
# Convert video/image from RGB to RGB
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Apply the mediapipe pose detection module for detection
results = pose.process(imgRGB)
print(results.pose_landmarks)
# Draw Landmarks
if results.pose_landmarks:
mpDraw.draw_landmarks(img, results.pose_landmarks, mpPose.POSE_CONNECTIONS)
cv2.imshow("Pose Detection", img)
if cv2.waitKey(1) & 0xFF == ord("x"):
break
#########################################################
# Release the capture once all the processing is done.
cap.release()
cv2.destroyAllWindows()