-
Notifications
You must be signed in to change notification settings - Fork 38
/
pose.py
55 lines (41 loc) · 1.47 KB
/
pose.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
import argparse
import mediapipe as mp
import numpy as np
from videosource import FileSource, WebcamSource
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=3)
def main(inp):
if inp is None:
source = WebcamSource()
else:
source = FileSource(inp)
with mp_pose.Pose(
min_detection_confidence=0.5, min_tracking_confidence=0.5
) as pose:
for idx, (frame, frame_rgb) in enumerate(source):
results = pose.process(frame_rgb)
if results.pose_landmarks:
mp_drawing.draw_landmarks(
frame,
results.pose_landmarks,
mp_pose.POSE_CONNECTIONS,
landmark_drawing_spec=drawing_spec,
connection_drawing_spec=drawing_spec,
)
# get landmarks as numpy
landmarks = results.pose_landmarks.landmark
np_landmarks = np.array(
[(lm.x, lm.y, lm.z, lm.visibility) for lm in landmarks]
)
print(np_landmarks.shape)
source.show(frame)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Choose video file otherwise webcam is used."
)
parser.add_argument(
"-i", metavar="path-to-file", type=str, help="Path to video file"
)
args = parser.parse_args()
main(args.i)