apirrone
commited on
Commit
·
380e46e
1
Parent(s):
f18d516
moving peopledetector in main file
Browse files
reachy_mini_red_light_green_light/main.py
CHANGED
|
@@ -11,7 +11,51 @@ from reachy_mini.reachy_mini import (
|
|
| 11 |
SLEEP_HEAD_JOINT_POSITIONS,
|
| 12 |
SLEEP_ANTENNAS_JOINT_POSITIONS,
|
| 13 |
)
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
class RedLightGreenLightApp(ReachyMiniApp):
|
|
|
|
| 11 |
SLEEP_HEAD_JOINT_POSITIONS,
|
| 12 |
SLEEP_ANTENNAS_JOINT_POSITIONS,
|
| 13 |
)
|
| 14 |
+
import cv2
|
| 15 |
+
import mediapipe as mp
|
| 16 |
+
|
| 17 |
+
UPPER_BODY_LANDMARKS = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class PeopleDetector:
|
| 21 |
+
def __init__(self, model_path="pose_landmarker_full.task", max_poses=5):
|
| 22 |
+
# Initialisation de MediaPipe Tasks
|
| 23 |
+
BaseOptions = mp.tasks.BaseOptions
|
| 24 |
+
PoseLandmarker = mp.tasks.vision.PoseLandmarker
|
| 25 |
+
PoseLandmarkerOptions = mp.tasks.vision.PoseLandmarkerOptions
|
| 26 |
+
VisionRunningMode = mp.tasks.vision.RunningMode
|
| 27 |
+
|
| 28 |
+
self.pose_landmarker = PoseLandmarker.create_from_options(
|
| 29 |
+
PoseLandmarkerOptions(
|
| 30 |
+
base_options=BaseOptions(model_asset_path=model_path),
|
| 31 |
+
running_mode=VisionRunningMode.IMAGE,
|
| 32 |
+
num_poses=max_poses,
|
| 33 |
+
)
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
def detect(self, frame, draw=True):
|
| 37 |
+
mp_image = mp.Image(
|
| 38 |
+
image_format=mp.ImageFormat.SRGB,
|
| 39 |
+
data=cv2.cvtColor(frame, cv2.COLOR_BGR2RGB),
|
| 40 |
+
)
|
| 41 |
+
result = self.pose_landmarker.detect(mp_image)
|
| 42 |
+
|
| 43 |
+
h, w, _ = frame.shape
|
| 44 |
+
detected_people = []
|
| 45 |
+
|
| 46 |
+
if result.pose_landmarks:
|
| 47 |
+
for person_landmarks in result.pose_landmarks:
|
| 48 |
+
person = {"landmarks": []}
|
| 49 |
+
for idx, lm in enumerate(person_landmarks):
|
| 50 |
+
if idx not in UPPER_BODY_LANDMARKS:
|
| 51 |
+
continue
|
| 52 |
+
cx, cy = int(lm.x * w), int(lm.y * h)
|
| 53 |
+
person["landmarks"].append((cx, cy))
|
| 54 |
+
if draw:
|
| 55 |
+
cv2.circle(frame, (cx, cy), 3, (0, 255, 0), -1)
|
| 56 |
+
detected_people.append(person)
|
| 57 |
+
|
| 58 |
+
return frame, detected_people
|
| 59 |
|
| 60 |
|
| 61 |
class RedLightGreenLightApp(ReachyMiniApp):
|