-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpose_testing.py
62 lines (53 loc) · 1.38 KB
/
pose_testing.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
51
52
53
54
55
56
57
58
59
60
61
62
import cv2
from ultralytics import YOLO
import numpy as np
# Load Model
pose_model = YOLO("yolov8s-pose.pt")
# Keypoint names
keypoint_names = [
"nose",
"left_eye",
"right_eye",
"left_ear",
"right_ear",
"left_shoulder",
"right_shoulder",
"left_elbow",
"right_elbow",
"left_wrist",
"right_wrist",
"left_hip",
"right_hip",
"left_knee",
"right_knee",
"left_ankle",
"right_ankle",
]
# Open the webcam
cap = cv2.VideoCapture(1)
while cap.isOpened():
success, frame = cap.read()
if success:
# Pose detection
pose_results = pose_model(frame, verbose=False, conf=0.5)
# Print each body coordinate as a dictionary
for person in pose_results:
keypoints = person.keypoints.data[0]
for keypoint, name in zip(keypoints, keypoint_names):
x, y, probability = keypoint
print(
{
"keypoint": name,
"x": x.item(),
"y": y.item(),
"probability": probability.item(),
}
)
pose_annotated_frame = person.plot()
cv2.imshow("Pose Detection", pose_annotated_frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
break
cap.release()
cv2.destroyAllWindows()