You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gesture_rec/ml_gestures/feature_extractor.py

27 lines
969 B
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import numpy as np
def normalize_landmarks(landmarks):
"""
Нормализует полный скелет MediaPipe (33 точки) с использованием x,y,z.
Центрирует относительно центра бёдер и масштабирует по росту.
Возвращает плоский вектор (99,) из x,y,z всех точек.
"""
lm = landmarks[:, :3].copy() # (33,3)
# Центр бёдер (индексы 23 и 24)
hip_center = (lm[23] + lm[24]) / 2
# Центр плеч (11 и 12)
shoulder_center = (lm[11] + lm[12]) / 2
# Рост расстояние от бёдер до плеч
height = np.linalg.norm(shoulder_center - hip_center)
if height < 1e-6:
height = 1.0
# Центрируем и масштабируем
lm_centered = lm - hip_center
lm_normalized = lm_centered / height
return lm_normalized.flatten() # (99,)