Spaces:
Sleeping
Sleeping
File size: 1,087 Bytes
e5b4dc5 |
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 |
import numpy as np
from numpy.linalg import norm
def normalize_landmarks(landmarks):
"""
Normalize the hand landmarks.
Parameters:
landmarks (numpy.ndarray): Array of hand landmarks.
Returns:
numpy.ndarray: Normalized landmarks.
"""
center = np.mean(landmarks, axis=0)
landmarks_centered = landmarks - center
std_dev = np.std(landmarks_centered, axis=0)
landmarks_normalized = landmarks_centered / std_dev
return np.nan_to_num(landmarks_normalized)
def calculate_angles(landmarks):
"""
Calculate angles between hand landmarks.
Parameters:
landmarks (numpy.ndarray): Array of hand landmarks.
Returns:
list: List of calculated angles.
"""
angles = []
for i in range(20):
for j in range(i + 1, 21):
vector = landmarks[j] - landmarks[i]
angle_x = np.arccos(np.clip(vector[0] / norm(vector), -1.0, 1.0))
angle_y = np.arccos(np.clip(vector[1] / norm(vector), -1.0, 1.0))
angles.extend([angle_x, angle_y])
return angles
|