swastikbansal commited on
Commit
1777546
·
verified ·
1 Parent(s): 7e05328

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +307 -177
utils.py CHANGED
@@ -1,178 +1,308 @@
1
- import cv2
2
- import mediapipe as mp
3
- import pickle
4
- import numpy as np
5
-
6
- class Utils:
7
- def __init__(self, axes):
8
- self.axes = axes
9
-
10
- def calculate_angle1(self, vec1, vec2):
11
- dot_product = np.dot(vec1, vec2)
12
- norm_vec1 = np.linalg.norm(vec1)
13
- norm_vec2 = np.linalg.norm(vec2)
14
- self.cosine_angle = dot_product / (norm_vec1 * norm_vec2)
15
- return self.cosine_angle
16
-
17
- def get_coordinates_safe(self, landmark, index):
18
- try:
19
- return np.array([landmark[index].x, landmark[index].y, landmark[index].z])
20
- except IndexError:
21
- return np.array([-1, -1, -1])
22
-
23
-
24
- def angle_between_vectors(self, v1, v2):
25
- dot_product = np.dot(v1, v2)
26
- magnitude_v1 = np.linalg.norm(v1)
27
- magnitude_v2 = np.linalg.norm(v2)
28
- cos_theta = dot_product / (magnitude_v1 * magnitude_v2)
29
- cos_theta = np.clip(cos_theta, -1.0, 1.0)
30
- self.theta = np.arccos(cos_theta)
31
- return np.degrees(self.theta)
32
-
33
- # Function to classify palm orientation
34
- def get_palm_orientation(self, normal):
35
- angles = {axis: self.angle_between_vectors(normal, direction) for axis, direction in self.axes.items()}
36
- # Find the axis with the smallest angle
37
- self.best_match_axis = min(angles, key=angles.get)
38
- return self.best_match_axis
39
-
40
-
41
- # Function to extract hand features (angles between vectors and axes)
42
- def extract_features(self, hand_landmarks, pose_landmarks=None):
43
- hand_pairs = [
44
- (1 , 3) , # Thumb
45
- (6 , 8 ), # Index finger
46
- (10, 12), # Middle finger
47
- (14, 16), # Ring finger
48
- (18, 20), # Pinky finger
49
- (0 , 9) # Palm direction
50
- ]
51
-
52
- self.features = []
53
- for pair in hand_pairs:
54
- landmark1 = hand_landmarks[pair[0]]
55
- landmark2 = hand_landmarks[pair[1]]
56
-
57
- vector = np.array([landmark2.x - landmark1.x, landmark2.y - landmark1.y, landmark2.z - landmark1.z])
58
- x_axis = np.array([1, 0, 0])
59
- y_axis = np.array([0, 1, 0])
60
- z_axis = np.array([0, 0, 1])
61
-
62
- angle_x = self.calculate_angle1(vector, x_axis)
63
- angle_y = self.calculate_angle1(vector, y_axis)
64
- angle_z = self.calculate_angle1(vector, z_axis)
65
-
66
- self.features.extend([angle_x, angle_y, angle_z])
67
-
68
- # Safe access to landmarks for 0, 5, and 17
69
- vector_0_to_5 = self.get_coordinates_safe(hand_landmarks, 5) - self.get_coordinates_safe(hand_landmarks, 0)
70
- vector_0_to_17 = self.get_coordinates_safe(hand_landmarks, 17) - self.get_coordinates_safe(hand_landmarks, 0)
71
-
72
- normal_vector = np.cross(vector_0_to_5, vector_0_to_17)
73
-
74
- normal_angle_x = self.calculate_angle1(normal_vector, x_axis)
75
- normal_angle_y = self.calculate_angle1(normal_vector, y_axis)
76
- normal_angle_z = self.calculate_angle1(normal_vector, z_axis)
77
-
78
- self.features.extend([normal_angle_x, normal_angle_y, normal_angle_z])
79
-
80
- # If pose landmarks are available, calculate the distance between nose and wrist
81
-
82
- nose_landmark = self.get_coordinates_safe(pose_landmarks, 0) # Nose is at index 0 in pose landmarks
83
- wrist_landmark = self.get_coordinates_safe(hand_landmarks, 0) # Wrist is at index 0 in hand landmarks
84
-
85
- # Calculate the distance in the x and y axes
86
- distance_x = abs(nose_landmark[0] - wrist_landmark[0])
87
- distance_y = abs(nose_landmark[1] - wrist_landmark[1])
88
-
89
- # Append the x and y distances as new features
90
- self.features.extend([distance_x, distance_y])
91
-
92
- return self.features
93
-
94
- #Initialize pose extraction functions
95
- def calculate_normal_safe(self,p1, p2, p3):
96
- # Check if any of the points is [-1, -1, -1] (default value for missing landmarks)
97
- if np.array_equal(p1, [-1, -1, -1]) or np.array_equal(p2, [-1, -1, -1]) or np.array_equal(p3, [-1, -1, -1]):
98
- return np.array([-1, -1, -1]) # Return [-1, -1, -1] if any point is missing
99
- else:
100
- return self.calculate_normal(p1, p2, p3) # Otherwise, calculate the normal as usual
101
-
102
- # Function to calculate angle between three points
103
- def calculate_angle2(self,p1, p2, p3):
104
- # Create vectors from points p1, p2, p3
105
- v1 = p1 - p2
106
- v2 = p3 - p2
107
-
108
- # Calculate the cosine of the angle using dot product
109
- self.cos_theta = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
110
-
111
- return self.cos_theta
112
-
113
- # Function to calculate the normal of the plane formed by three points
114
- def calculate_normal(self, p1, p2, p3):
115
- # Vectors on the plane
116
- v1 = p2 - p1
117
- v2 = p3 - p1
118
-
119
- # Cross product gives the normal vector
120
- self.normal = np.cross(v1, v2)
121
-
122
- # Normalize the normal vector
123
- self.normal = self.normal / np.linalg.norm(self.normal)
124
-
125
- return self.normal
126
-
127
- # Function to calculate the angle between the normal and each of the axes
128
- def calculate_normal_angles(self,normal):
129
- # Calculate angles with x, y, z axes
130
- self.cos_values = []
131
- for axis in np.eye(3): # x, y, z unit vectors
132
- cos_value = np.dot(normal, axis)
133
- self.cos_values.append(cos_value)
134
- return self.cos_values
135
-
136
- # Function to calculate the x and y distance between two points
137
- def calculate_xy_distance(self, p1, p2):
138
- self.x_distance = abs(p1[0] - p2[0])
139
- self.y_distance = abs(p1[1] - p2[1])
140
- return self.x_distance, self.y_distance
141
-
142
- # Function to extract the pose features
143
- def extract_pose_features(self, landmarks):
144
- # Define the landmark indices for the required sets of points (using Pose landmark indices)
145
- points_sets = {
146
- "angle_11_12_14": (self.get_coordinates_safe(landmarks, 11), self.get_coordinates_safe(landmarks, 12), self.get_coordinates_safe(landmarks, 14)), # Left shoulder, right shoulder, right elbow
147
- "angle_12_14_16": (self.get_coordinates_safe(landmarks, 12), self.get_coordinates_safe(landmarks, 11), self.get_coordinates_safe(landmarks, 13)), # Right shoulder, right elbow, right wrist
148
- "angle_11_13_15": (self.get_coordinates_safe(landmarks, 11), self.get_coordinates_safe(landmarks, 13), self.get_coordinates_safe(landmarks, 15)), # Left shoulder, left elbow, left wrist
149
- "angle_13_15_17": (self.get_coordinates_safe(landmarks, 12), self.get_coordinates_safe(landmarks, 14), self.get_coordinates_safe(landmarks, 16)), # Left elbow, left wrist, left hand
150
- "normal_1": (self.get_coordinates_safe(landmarks, 15), self.get_coordinates_safe(landmarks, 17), self.get_coordinates_safe(landmarks, 19)), # Plane formed by left shoulder, left hip, left knee
151
- "normal_2": (self.get_coordinates_safe(landmarks, 16), self.get_coordinates_safe(landmarks, 18), self.get_coordinates_safe(landmarks, 20)) # Plane formed by right shoulder, right hip, right knee
152
- }
153
-
154
- # Calculate the angles between the specific sets of points
155
- self.angles = []
156
- for key, (p1, p2, p3) in points_sets.items():
157
- if key.startswith("angle"):
158
- angle = self.calculate_angle2(p1, p2, p3)
159
- self.angles.append(angle)
160
-
161
- # Calculate normals and angles with axes
162
- for key, (p1, p2, p3) in points_sets.items():
163
- if key.startswith("normal"):
164
- normal = self.calculate_normal_safe(p1, p2, p3) # Safe normal calculation
165
- if np.array_equal(normal, [-1, -1, -1]):
166
- # If normal is [-1, -1, -1], it indicates missing points, so append [-1, -1, -1] for each axis angle
167
- self.angles.extend([-1, -1, -1])
168
- else:
169
- normal_angles = self.calculate_normal_angles(normal)
170
- self.angles.extend(normal_angles) # Append angles with x, y, z axes
171
-
172
- # Add the distance between points 15 (left wrist) and 16 (right wrist)
173
- p15 = self.get_coordinates_safe(landmarks, 15) # Left wrist
174
- p16 = self.get_coordinates_safe(landmarks, 16) # Right wrist
175
- x_distance, y_distance = self.calculate_xy_distance(p15, p16)
176
- self.angles.extend([x_distance, y_distance]) # Append x and y distance to the feature list
177
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  return self.angles
 
1
+ import numpy as np
2
+ import time
3
+
4
+ class Utils:
5
+ def __init__(self, axes, restSpeed, minPoints, requiredFrames):
6
+ self.axes = axes
7
+ self.REST_SPEED_THRESHOLD = restSpeed # pixels/second
8
+ self.MIN_POINTS_FOR_REST = minPoints
9
+ self.REQUIRED_CONSECUTIVE_FRAMES = requiredFrames
10
+
11
+ self.rest_buffer_frame = 0
12
+ # persistent state used across consecutive calls to is_resting
13
+ self.prev_positions = {
14
+ "positions": {}, # dict e.g. {"left_wrist": np.array([...]), ...}
15
+ "timestamp": None,
16
+ "counters": { # consecutive low-speed frame counters per key
17
+ "left_wrist": 0,
18
+ "right_wrist": 0,
19
+ "left_shoulder": 0,
20
+ "right_shoulder": 0
21
+ },
22
+ "rest_start_time": None
23
+ }
24
+
25
+ def _landmark_to_pixel(self, landmark, img_shape):
26
+ """Convert normalized landmark to pixel (x,y)."""
27
+ h, w = img_shape[0], img_shape[1]
28
+ return np.array([landmark.x * w, landmark.y * h], dtype=float)
29
+
30
+ # Replace previous is_resting with time-based version
31
+ def is_resting(self, res_hands, img_shape, rest_delay_seconds: float = 2.0, fps: float = None):
32
+ """
33
+ Time-based rest detection.
34
+ Returns True if average landmark speed stays below REST_SPEED_THRESHOLD
35
+ for at least rest_delay_seconds.
36
+ """
37
+ current_time = time.time()
38
+ points = {}
39
+
40
+ # Hands: get wrist landmark (index 0) if available
41
+ if getattr(res_hands, "multi_hand_landmarks", None) and getattr(res_hands, "multi_handedness", None):
42
+ for hand_landmarks, handedness in zip(res_hands.multi_hand_landmarks, res_hands.multi_handedness):
43
+ label = handedness.classification[0].label
44
+ try:
45
+ wrist = self._landmark_to_pixel(hand_landmarks.landmark[0], img_shape)
46
+ except Exception:
47
+ continue
48
+
49
+ if label == 'Left':
50
+ points['left_wrist'] = wrist
51
+ elif label == 'Right':
52
+ points['right_wrist'] = wrist
53
+
54
+ # Initialize previous timestamp if missing
55
+ if self.prev_positions['timestamp'] is None:
56
+ self.prev_positions['timestamp'] = current_time
57
+ self.prev_positions['positions'].update({k: v for k, v in points.items()})
58
+ self.prev_positions['rest_start_time'] = None
59
+ return False
60
+
61
+ # No landmarks detected -> not resting (reset)
62
+ if len(points) < 1:
63
+ self.prev_positions['timestamp'] = current_time
64
+ self.prev_positions['positions'].update({k: v for k, v in points.items()})
65
+ self.prev_positions['rest_start_time'] = None
66
+ # reset counters for keys that are missing
67
+ for k in self.prev_positions['counters']:
68
+ if k not in points:
69
+ self.prev_positions['counters'][k] = 0
70
+ return False
71
+
72
+ dt = current_time - self.prev_positions['timestamp']
73
+ if dt <= 0:
74
+ self.prev_positions['timestamp'] = current_time
75
+ self.prev_positions['positions'].update({k: v for k, v in points.items()})
76
+ self.prev_positions['rest_start_time'] = None
77
+ return False
78
+
79
+ speeds = []
80
+ speed_map = {}
81
+
82
+ # compute speeds only where previous positions exist
83
+ for key, cur_pos in points.items():
84
+ prev_pos = self.prev_positions['positions'].get(key)
85
+ if prev_pos is not None:
86
+ dist = np.linalg.norm(cur_pos - prev_pos)
87
+ speed = dist / dt
88
+ speeds.append(speed)
89
+ speed_map[key] = speed
90
+
91
+ # update timestamp and previous positions for next call
92
+ self.prev_positions['timestamp'] = current_time
93
+ self.prev_positions['positions'].update({k: v for k, v in points.items()})
94
+
95
+ # reset counters for disappeared landmarks
96
+ for k in list(self.prev_positions['counters'].keys()):
97
+ if k not in speed_map:
98
+ self.prev_positions['counters'][k] = 0
99
+
100
+ # Optionally scale threshold for very low FPS if fps provided
101
+ adjusted_threshold = self.REST_SPEED_THRESHOLD
102
+ if fps is not None and fps > 0:
103
+ adjusted_threshold = self.REST_SPEED_THRESHOLD * (30.0 / max(fps, 1.0))
104
+
105
+ # Using avg speed to detect on enough landmarks
106
+ if len(speeds) >= self.MIN_POINTS_FOR_REST:
107
+ avg_speed = float(np.mean(speeds))
108
+ if avg_speed < adjusted_threshold:
109
+ if self.prev_positions['rest_start_time'] is None:
110
+ self.prev_positions['rest_start_time'] = current_time
111
+ # Check duration
112
+ if (current_time - self.prev_positions['rest_start_time']) >= rest_delay_seconds:
113
+ return True
114
+ else:
115
+ # Reset rest tracking if movement detected
116
+ self.prev_positions['rest_start_time'] = None
117
+ for k in self.prev_positions['counters']:
118
+ self.prev_positions['counters'][k] = 0
119
+ return False
120
+
121
+ # Single landmark case: treat similarly
122
+ if len(speeds) == 1:
123
+ key = next(iter(speed_map))
124
+ speed = speed_map[key]
125
+ if speed < adjusted_threshold:
126
+ if self.prev_positions['rest_start_time'] is None:
127
+ self.prev_positions['rest_start_time'] = current_time
128
+ if (current_time - self.prev_positions['rest_start_time']) >= rest_delay_seconds:
129
+ return True
130
+ else:
131
+ self.prev_positions['rest_start_time'] = None
132
+ self.prev_positions['counters'][key] = 0
133
+ return False
134
+
135
+ # default
136
+ self.prev_positions['rest_start_time'] = None
137
+ return False
138
+
139
+
140
+ def calculate_angle1(self, vec1, vec2):
141
+ dot_product = np.dot(vec1, vec2)
142
+ norm_vec1 = np.linalg.norm(vec1)
143
+ norm_vec2 = np.linalg.norm(vec2)
144
+ self.cosine_angle = dot_product / (norm_vec1 * norm_vec2) if norm_vec1 and norm_vec2 else 0
145
+ return self.cosine_angle
146
+
147
+ def get_coordinates_safe(self, landmark, index):
148
+ try:
149
+ return np.array([landmark[index].x, landmark[index].y, landmark[index].z])
150
+ except IndexError:
151
+ return np.array([-1, -1, -1])
152
+
153
+
154
+ def angle_between_vectors(self, v1, v2):
155
+ dot_product = np.dot(v1, v2)
156
+ magnitude_v1 = np.linalg.norm(v1)
157
+ magnitude_v2 = np.linalg.norm(v2)
158
+ cos_theta = dot_product / (magnitude_v1 * magnitude_v2)
159
+ cos_theta = np.clip(cos_theta, -1.0, 1.0)
160
+ self.theta = np.arccos(cos_theta)
161
+ return np.degrees(self.theta)
162
+
163
+ # Function to classify palm orientation
164
+ def get_palm_orientation(self, normal):
165
+ angles = {axis: self.angle_between_vectors(normal, direction) for axis, direction in self.axes.items()}
166
+ # Find the axis with the smallest angle
167
+ self.best_match_axis = min(angles, key=angles.get)
168
+ return self.best_match_axis
169
+
170
+
171
+ # Function to extract hand features (angles between vectors and axes)
172
+ def extract_features(self, hand_landmarks, pose_landmarks=None):
173
+ hand_pairs = [
174
+ (1 , 3) , # Thumb
175
+ (6 , 8 ), # Index finger
176
+ (10, 12), # Middle finger
177
+ (14, 16), # Ring finger
178
+ (18, 20), # Pinky finger
179
+ (0 , 9) # Palm direction
180
+ ]
181
+
182
+ self.features = []
183
+ for pair in hand_pairs:
184
+ landmark1 = hand_landmarks[pair[0]]
185
+ landmark2 = hand_landmarks[pair[1]]
186
+
187
+ vector = np.array([landmark2.x - landmark1.x, landmark2.y - landmark1.y, landmark2.z - landmark1.z])
188
+ x_axis = np.array([1, 0, 0])
189
+ y_axis = np.array([0, 1, 0])
190
+ z_axis = np.array([0, 0, 1])
191
+
192
+ angle_x = self.calculate_angle1(vector, x_axis)
193
+ angle_y = self.calculate_angle1(vector, y_axis)
194
+ angle_z = self.calculate_angle1(vector, z_axis)
195
+
196
+ self.features.extend([angle_x, angle_y, angle_z])
197
+
198
+ # Safe access to landmarks for 0, 5, and 17
199
+ vector_0_to_5 = self.get_coordinates_safe(hand_landmarks, 5) - self.get_coordinates_safe(hand_landmarks, 0)
200
+ vector_0_to_17 = self.get_coordinates_safe(hand_landmarks, 17) - self.get_coordinates_safe(hand_landmarks, 0)
201
+
202
+ normal_vector = np.cross(vector_0_to_5, vector_0_to_17)
203
+
204
+ normal_angle_x = self.calculate_angle1(normal_vector, x_axis)
205
+ normal_angle_y = self.calculate_angle1(normal_vector, y_axis)
206
+ normal_angle_z = self.calculate_angle1(normal_vector, z_axis)
207
+
208
+ self.features.extend([normal_angle_x, normal_angle_y, normal_angle_z])
209
+
210
+ # If pose landmarks are available, calculate the distance between nose and wrist
211
+
212
+ nose_landmark = self.get_coordinates_safe(pose_landmarks, 0) # Nose is at index 0 in pose landmarks
213
+ wrist_landmark = self.get_coordinates_safe(hand_landmarks, 0) # Wrist is at index 0 in hand landmarks
214
+
215
+ # Calculate the distance in the x and y axes
216
+ distance_x = abs(nose_landmark[0] - wrist_landmark[0])
217
+ distance_y = abs(nose_landmark[1] - wrist_landmark[1])
218
+
219
+ # Append the x and y distances as new features
220
+ self.features.extend([distance_x, distance_y])
221
+
222
+ return self.features
223
+
224
+ #Initialize pose extraction functions
225
+ def calculate_normal_safe(self,p1, p2, p3):
226
+ # Check if any of the points is [-1, -1, -1] (default value for missing landmarks)
227
+ if np.array_equal(p1, [-1, -1, -1]) or np.array_equal(p2, [-1, -1, -1]) or np.array_equal(p3, [-1, -1, -1]):
228
+ return np.array([-1, -1, -1]) # Return [-1, -1, -1] if any point is missing
229
+ else:
230
+ return self.calculate_normal(p1, p2, p3) # Otherwise, calculate the normal as usual
231
+
232
+ # Function to calculate angle between three points
233
+ def calculate_angle2(self,p1, p2, p3):
234
+ # Create vectors from points p1, p2, p3
235
+ v1 = p1 - p2
236
+ v2 = p3 - p2
237
+
238
+ # Calculate the cosine of the angle using dot product
239
+ self.cos_theta = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
240
+
241
+ return self.cos_theta
242
+
243
+ # Function to calculate the normal of the plane formed by three points
244
+ def calculate_normal(self, p1, p2, p3):
245
+ # Vectors on the plane
246
+ v1 = p2 - p1
247
+ v2 = p3 - p1
248
+
249
+ # Cross product gives the normal vector
250
+ self.normal = np.cross(v1, v2)
251
+
252
+ # Normalize the normal vector
253
+ self.normal = self.normal / np.linalg.norm(self.normal)
254
+
255
+ return self.normal
256
+
257
+ # Function to calculate the angle between the normal and each of the axes
258
+ def calculate_normal_angles(self,normal):
259
+ # Calculate angles with x, y, z axes
260
+ self.cos_values = []
261
+ for axis in np.eye(3): # x, y, z unit vectors
262
+ cos_value = np.dot(normal, axis)
263
+ self.cos_values.append(cos_value)
264
+ return self.cos_values
265
+
266
+ # Function to calculate the x and y distance between two points
267
+ def calculate_xy_distance(self, p1, p2):
268
+ self.x_distance = abs(p1[0] - p2[0])
269
+ self.y_distance = abs(p1[1] - p2[1])
270
+ return self.x_distance, self.y_distance
271
+
272
+ # Function to extract the pose features
273
+ def extract_pose_features(self, landmarks):
274
+ # Define the landmark indices for the required sets of points (using Pose landmark indices)
275
+ points_sets = {
276
+ "angle_11_12_14": (self.get_coordinates_safe(landmarks, 11), self.get_coordinates_safe(landmarks, 12), self.get_coordinates_safe(landmarks, 14)), # Left shoulder, right shoulder, right elbow
277
+ "angle_12_14_16": (self.get_coordinates_safe(landmarks, 12), self.get_coordinates_safe(landmarks, 11), self.get_coordinates_safe(landmarks, 13)), # Right shoulder, right elbow, right wrist
278
+ "angle_11_13_15": (self.get_coordinates_safe(landmarks, 11), self.get_coordinates_safe(landmarks, 13), self.get_coordinates_safe(landmarks, 15)), # Left shoulder, left elbow, left wrist
279
+ "angle_13_15_17": (self.get_coordinates_safe(landmarks, 12), self.get_coordinates_safe(landmarks, 14), self.get_coordinates_safe(landmarks, 16)), # Left elbow, left wrist, left hand
280
+ "normal_1": (self.get_coordinates_safe(landmarks, 15), self.get_coordinates_safe(landmarks, 17), self.get_coordinates_safe(landmarks, 19)), # Plane formed by left shoulder, left hip, left knee
281
+ "normal_2": (self.get_coordinates_safe(landmarks, 16), self.get_coordinates_safe(landmarks, 18), self.get_coordinates_safe(landmarks, 20)) # Plane formed by right shoulder, right hip, right knee
282
+ }
283
+
284
+ # Calculate the angles between the specific sets of points
285
+ self.angles = []
286
+ for key, (p1, p2, p3) in points_sets.items():
287
+ if key.startswith("angle"):
288
+ angle = self.calculate_angle2(p1, p2, p3)
289
+ self.angles.append(angle)
290
+
291
+ # Calculate normals and angles with axes
292
+ for key, (p1, p2, p3) in points_sets.items():
293
+ if key.startswith("normal"):
294
+ normal = self.calculate_normal_safe(p1, p2, p3) # Safe normal calculation
295
+ if np.array_equal(normal, [-1, -1, -1]):
296
+ # If normal is [-1, -1, -1], it indicates missing points, so append [-1, -1, -1] for each axis angle
297
+ self.angles.extend([-1, -1, -1])
298
+ else:
299
+ normal_angles = self.calculate_normal_angles(normal)
300
+ self.angles.extend(normal_angles) # Append angles with x, y, z axes
301
+
302
+ # Add the distance between points 15 (left wrist) and 16 (right wrist)
303
+ p15 = self.get_coordinates_safe(landmarks, 15) # Left wrist
304
+ p16 = self.get_coordinates_safe(landmarks, 16) # Right wrist
305
+ x_distance, y_distance = self.calculate_xy_distance(p15, p16)
306
+ self.angles.extend([x_distance, y_distance]) # Append x and y distance to the feature list
307
+
308
  return self.angles