7 Commits
Author SHA1 Message Date
gestures3 b745a2018b poses_detection 2026-07-22 11:30:29 +03:00
gestures3 18191cb490 nos 2026-07-10 16:58:11 +03:00
gestures3 bc160001bc last dummy 2026-07-10 12:09:20 +03:00
gestures6 e74f1b09d7 changed cross detection to silly and fixed deps 2026-07-03 17:18:54 +03:00
Eliza Moscovskaya 1b9a1b2c3d Update 'README.md' 2026-07-03 10:10:42 +03:00
Eliza Moscovskaya d3d6c647a6 Update 'README.md' 2026-07-02 15:34:55 +03:00
moscovskayaliza b0f04daa78 hotfix to make it works with ros 2026-06-25 18:16:58 +03:00
4 changed files with 138 additions and 43 deletions
+10 -5
View File
@@ -52,24 +52,28 @@ cd gesture_rec
git submodule update --init --recursive
```
### 2. Создание виртуального окружения
Рекомендуется использовать виртуальное окружение и Python 3.11:
Рекомендуется использовать виртуальное окружение и Python 3.10:
```
python3.11 -m venv venv
python3.10 -m venv venv
source venv/bin/activate
```
Если у вас не скачен питон этой версии, сначала выполните:
```
sudo apt install python3.11 python3.11-venv
sudo apt install python3.10 python3.10-venv
```
Если у нас не устанавливается питон 3.11, то это потому что он отсутствует в официальных репозиториях по умолчанию, надо добавить репозиторий перед скачиванием:
Если у нас не устанавливается питон 3.10, то это потому что он отсутствует в официальных репозиториях по умолчанию, надо добавить репозиторий перед скачиванием:
```
sudo apt update && sudo apt install -y software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
```
To install pip:
sudo apt install -y python3-pip
### 3. Установка зависимостей
### 3.1. Способ 1
@@ -86,6 +90,7 @@ sudo apt update
pip install --upgrade pip
pip install numpy==1.24.3
pip install pandas==2.0.3
pip install pyyaml
pip install opencv-python==4.12.0.88
pip install opencv-python-headless==4.12.0.88
pip install matplotlib==3.7.5
@@ -128,7 +133,7 @@ pip install protobuf==3.20.3
2. Если будет проблема с функцией cv2.imshow() то, переустановите cv2 без заголовков:
```
pip uninstall opencv-python pip install opencv-python-headless
pip uninstall opencv-python opencv-python-headless
pip install opencv-python==4.12.0.88
```
3. Если будет ошибка с PIL, попробуйте обновить библиотеку:
+38 -21
View File
@@ -55,7 +55,7 @@ class ArmController:
def _horizontal_displacement_rel(self, landmarks, side):
"""
Нормированное горизонтальное смещение запястья относительно плеча.
Нормированное горизонтальное смещение запястья относительно плеча.Ширина плеч для нормировки горизонтальных смещен
Сторона `side` — это реальная сторона руки
"""
s_idx, w_idx = self._get_side_indices(side)
@@ -100,27 +100,44 @@ class ArmController:
print("Руки не видны")
return 0.0, 0.0
linear_side = self.config['linear_arm']
angular_side = self.config['angular_arm']
lin_rel = self._horizontal_displacement_rel(landmarks, linear_side)
ang_rel = self._vertical_displacement_rel(landmarks, angular_side)
if self.debug:
print(f"lin_rel={lin_rel:.3f}, ang_rel={ang_rel:.3f}")
r_sh_z = landmarks[12][2]
r_wr_z = landmarks[16][2]
r_sh_z_divided = (landmarks[12][2] + landmarks[11][2])/2
nose_z = landmarks[0][2]
nose_and_sh_distance = r_sh_z_divided - nose_z
arm_forward = r_sh_z - r_wr_z
if arm_forward < 3*nose_and_sh_distance:
#print(f"landmarks[12][2] {landmarks[12][2] - landmarks[16][2]}")
linear_side = self.config['linear_arm']
angular_side = self.config['angular_arm']
#lin_rel = self._horizontal_displacement_rel(landmarks, linear_side)
lin_rel = self._vertical_displacement_rel(landmarks, linear_side)
ang_rel = self._vertical_displacement_rel(landmarks, angular_side)
if self.debug:
print(f"lin_rel={lin_rel:.3f}, ang_rel={ang_rel:.3f}")
# Линейная скорость
if abs(lin_rel) < self.dead_zone:
linear = 0.0
else:
lin_rel_clipped = np.clip(lin_rel, -1.0, 1.0)
linear = lin_rel_clipped * self.config['max_speed_linear']
# Угловая скорость
if abs(ang_rel) < self.dead_zone:
angular = 0.0
else:
ang_rel_clipped = np.clip(ang_rel, -1.0, 1.0)
angular = ang_rel_clipped * self.config['max_speed_angular']
return linear, angular
# Линейная скорость (только вперёд)
if lin_rel < self.dead_zone:
linear = 0.0
else:
linear = min(lin_rel, 1.0) * self.config['max_speed_linear']
# Угловая скорость
if abs(ang_rel) < self.dead_zone:
angular = 0.0
else:
ang_rel_clipped = np.clip(ang_rel, -1.0, 1.0)
angular = ang_rel_clipped * self.config['max_speed_angular']
return linear, angular
return 0.0, 0.0
+89 -17
View File
@@ -1,10 +1,10 @@
import numpy as np
from ml_gestures.predict import MLGesturePredictor
class SpecialGestureDetector:
def __init__(self, mode='geometric', model_path=None, class_names=None):
self.mode = mode
if mode == 'ml':
from ml_gestures.predict import MLGesturePredictor
if model_path is None or class_names is None:
raise ValueError("Для ML нужны model_path и class_names")
self.ml_predictor = MLGesturePredictor(model_path, class_names)
@@ -54,7 +54,7 @@ class SpecialGestureDetector:
l_hip = landmarks[idx['left_hip']][:2]
r_hip = landmarks[idx['right_hip']][:2]
nose = np.array(landmarks[idx['nose']][:2])
shoulder_center_y = (l_sh[1] + r_sh[1]) / 2
hip_center_y = (l_hip[1] + r_hip[1]) / 2
torso_height = hip_center_y - shoulder_center_y
@@ -74,11 +74,30 @@ class SpecialGestureDetector:
v2 = wrist - elbow
return angle_between_vectors(v1, v2)
def segments_intersect(p1, p2, p3, p4):
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o [1])* (b[0] - o[0])
d1 = cross(p3, p4, p1)
d2 = cross(p3, p4, p2)
d3 = cross(p1, p2, p3)
d4 = cross(p1, p2, p4)
return (d1 * d2 < 0) and (d3 * d4 < 0)
def line_intersection(p1, p2, p3, p4):
d1 = p2 - p1
d2 = p4 -p3
denom = d1[0] * d2[1] - d1[1] * d2[0]
if abs(denom) < 1e-6:
return None
t = ((p3[0] - p1[0]) * d2[1] - (p3[1] - p1[1]) * d2[0]) / denom
return p1 + t * d1
# ---- Вычисляем углы ----
l_angle = elbow_angle(l_sh, l_el, l_wr) # угол в левом локте
r_angle = elbow_angle(r_sh, r_el, r_wr) # угол в правом локте
# ---- КРЕСТ ----
'''
# 1. Оба локтя сильно согнуты (< 100°)
elbows_bent = (l_angle < 100 and r_angle < 100)
# 2. Левое запястье правее правого (перекрест)
@@ -90,27 +109,80 @@ class SpecialGestureDetector:
)
cross = elbows_bent and wrists_crossed and wrists_at_chest
if cross:
return 'cross'
'''
forearms_cross = segments_intersect(l_el, l_wr, r_el, r_wr)
intersection = line_intersection(l_el, l_wr, r_el, r_wr)
intersection_on_chest = False
if intersection is not None:
intersection_on_chest = (shoulder_center_y - 0.3 * torso_height < intersection[1] < hip_center_y + 0.3 * torso_height)
cross = forearms_cross and intersection_on_chest
if cross:
return 'cross'
# ---- ДОМИК ----
# 1. Запястья выше носа
wrists_above_nose = (l_wr[1] < nose[1] and r_wr[1] < nose[1])
## ---- ДОМИК ----
## 1. Запястья выше носа
#wrists_above_nose = (l_wr[1] < nose[1] and r_wr[1] < nose[1])
## 2. Локти выше плеч (верхняя граница плеч – min по Y среди плеч)
#shoulders_top_y = min(l_sh[1], r_sh[1])
#elbows_above_shoulders = (l_el[1] < shoulders_top_y and r_el[1] < shoulders_top_y)
## 3. Расстояние между локтями > расстояние между плечами
#elbow_distance = np.linalg.norm(l_el - r_el)
#elbows_far_apart = elbow_distance > shoulder_width
## 4. Расстояние между запястьями < половины ширины плеч
#wrist_distance = np.linalg.norm(l_wr - r_wr)
#wrists_near = wrist_distance < 0.5 * shoulder_width
#dome = wrists_above_nose and elbows_above_shoulders and elbows_far_apart and wrists_near
#if dome:
#return 'dome'
# ---- ЛАДОШКА ----
#r_sh_z = landmarks[idx['right_shoulder']][2]
#r_wr_z = landmarks[idx['right_wrist']][2]
#r_el_z = landmarks[idx['right_elbow']][2]
##1. правая рука почти выпрямлена
#wrist_at_shoulder_y = abs(r_wr[1] - r_sh[1]) < 0.4 * torso_height
#wrist_at_shoulder_x = abs(r_wr[0] - r_sh[0]) < 0.5 * shoulder_width
#r_sh_z_divided = (landmarks[12][2] + landmarks[11][2])/2
#nose_z = landmarks[0][2]
#nose_and_sh_distance = r_sh_z_divided - nose_z
#arm_forward = r_sh_z - r_wr_z
#print(f"arm_forward = {round(arm_forward, 3)} and nose_and_sh_distance = {round(nose_and_sh_distance, 3)}")
#if wrist_at_shoulder_y and wrist_at_shoulder_x and (arm_forward > 3.5*nose_and_sh_distance):
#return "ladoshka"
# ---- Рука к носу ----
nose_x = landmarks[0][0]
nose_y = landmarks[0][1]
wrist_at_nose_x = abs(r_wr[0] - nose_x) < 0.5 * shoulder_width
wrist_at_nose_y = abs(r_wr[1] - nose_y) < 0.2 * torso_height
if wrist_at_nose_x and wrist_at_nose_y:
return "kulak-nos"
# ---- Рука к левому плечу ----
wrist_at_shoulder_x = abs(r_wr[0] - l_sh[0]) < 0.2 * shoulder_width
wrist_at_shoulder_y = abs(r_wr[1] - l_sh[1]) < 0.2 * torso_height
if wrist_at_shoulder_x and wrist_at_shoulder_y:
return "wrist-shoulder"
# 2. Локти выше плеч (верхняя граница плеч – min по Y среди плеч)
shoulders_top_y = min(l_sh[1], r_sh[1])
elbows_above_shoulders = (l_el[1] < shoulders_top_y and r_el[1] < shoulders_top_y)
# 3. Расстояние между локтями > расстояние между плечами
elbow_distance = np.linalg.norm(l_el - r_el)
elbows_far_apart = elbow_distance > shoulder_width
# 4. Расстояние между запястьями < половины ширины плеч
wrist_distance = np.linalg.norm(l_wr - r_wr)
wrists_near = wrist_distance < 0.5 * shoulder_width
dome = wrists_above_nose and elbows_above_shoulders and elbows_far_apart and wrists_near
if dome:
return 'dome'
return 'none'
+1
View File
@@ -6,6 +6,7 @@ pip install --upgrade pip
pip install numpy==1.24.3
pip install pandas==2.0.3
pip install pyyaml==6.0.3
pip install opencv-python==4.12.0.88
pip install opencv-python-headless==4.12.0.88
pip install matplotlib==3.7.5