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