-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeatures.py
More file actions
43 lines (35 loc) · 1.47 KB
/
Copy pathfeatures.py
File metadata and controls
43 lines (35 loc) · 1.47 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
import math
def append_landmarks(features, landmarks, anchor, scale, expected_count, use_visibility=False):
if landmarks:
for lm in landmarks.landmark:
features.extend([
(lm.x - anchor[0]) / scale,
(lm.y - anchor[1]) / scale,
(lm.z - anchor[2]) / scale,
])
if use_visibility:
features.append(lm.visibility)
else:
values_per_point = 4 if use_visibility else 3
features.extend([0.0] * (expected_count * values_per_point))
def extract_features(pose_landmarks, left_hand_landmarks, right_hand_landmarks):
if not pose_landmarks:
return None
left_shoulder = pose_landmarks.landmark[11]
right_shoulder = pose_landmarks.landmark[12]
anchor = (
(left_shoulder.x + right_shoulder.x) / 2.0,
(left_shoulder.y + right_shoulder.y) / 2.0,
(left_shoulder.z + right_shoulder.z) / 2.0,
)
shoulder_dist = math.sqrt(
(left_shoulder.x - right_shoulder.x) ** 2
+ (left_shoulder.y - right_shoulder.y) ** 2
+ (left_shoulder.z - right_shoulder.z) ** 2
)
scale = max(shoulder_dist, 1e-6)
features = []
append_landmarks(features, pose_landmarks, anchor, scale, expected_count=33, use_visibility=True)
append_landmarks(features, left_hand_landmarks, anchor, scale, expected_count=21)
append_landmarks(features, right_hand_landmarks, anchor, scale, expected_count=21)
return features