apirrone
commited on
Commit
·
13808fa
1
Parent(s):
646f374
lookat image
Browse files
reachy_mini_red_light_green_light/main.py
CHANGED
@@ -11,28 +11,27 @@ from reachy_mini.reachy_mini import (
|
|
11 |
SLEEP_HEAD_JOINT_POSITIONS,
|
12 |
SLEEP_ANTENNAS_JOINT_POSITIONS,
|
13 |
)
|
14 |
-
import cv2
|
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()
|
25 |
-
cap = cv2.VideoCapture(0)
|
26 |
if cap is None:
|
27 |
raise RuntimeError("No camera found. Please connect a camera.")
|
28 |
|
29 |
# arbitrary 3 maximum people are tracked. Maybe make it a parameter?
|
30 |
pose_landmarker_path: str = str(
|
31 |
-
files(reachy_mini_red_light_green_light).joinpath(
|
32 |
-
|
33 |
-
|
34 |
-
model_path=pose_landmarker_path, max_poses=3
|
35 |
)
|
|
|
36 |
|
37 |
def sequence():
|
38 |
time.sleep(1)
|
@@ -113,7 +112,6 @@ class RedLightGreenLightApp(ReachyMiniApp):
|
|
113 |
if len(buffer) > 0:
|
114 |
if time.time() - last_watched >= (scan_for / (len(buffer) + 2)):
|
115 |
print("LOOK")
|
116 |
-
# TODO replace with reachy_mini.look_at_image
|
117 |
selected_to_watch = np.random.randint(0, len(buffer))
|
118 |
left_shoulder = buffer[selected_to_watch][-1][0]
|
119 |
r_shoulder = buffer[selected_to_watch][-1][1]
|
@@ -121,23 +119,26 @@ class RedLightGreenLightApp(ReachyMiniApp):
|
|
121 |
(left_shoulder[0] + r_shoulder[0]) // 2,
|
122 |
(left_shoulder[1] + r_shoulder[1]) // 2,
|
123 |
)
|
124 |
-
|
125 |
-
|
126 |
-
((look_at_px[0] / frame.shape[1]) - 0.5) * 2,
|
127 |
-
((look_at_px[1] / frame.shape[0]) - 0.5) * 2,
|
128 |
-
) # Normalize to [-1, 1]
|
129 |
-
yaw_range = [-80, 80]
|
130 |
-
target_yaw = (
|
131 |
-
normalized_look_at[0] * (yaw_range[1] - yaw_range[0]) / 2
|
132 |
-
+ (yaw_range[1] + yaw_range[0]) / 2
|
133 |
-
)
|
134 |
-
pose = create_head_pose(
|
135 |
-
yaw=-target_yaw,
|
136 |
-
)
|
137 |
-
reachy_mini.goto_target(
|
138 |
-
head=pose, antennas=[0.5, 0.0], duration=0.3
|
139 |
)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
last_watched = time.time()
|
142 |
buffer = []
|
143 |
moved = []
|
|
|
11 |
SLEEP_HEAD_JOINT_POSITIONS,
|
12 |
SLEEP_ANTENNAS_JOINT_POSITIONS,
|
13 |
)
|
|
|
|
|
14 |
from importlib.resources import files
|
15 |
import reachy_mini_red_light_green_light
|
16 |
from reachy_mini_red_light_green_light.people_detector import PeopleDetector
|
17 |
|
18 |
UPPER_BODY_LANDMARKS = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
|
19 |
|
20 |
+
|
21 |
class RedLightGreenLightApp(ReachyMiniApp):
|
22 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
23 |
# cap = find_camera()
|
24 |
+
cap = cv2.VideoCapture(0) # debug
|
25 |
if cap is None:
|
26 |
raise RuntimeError("No camera found. Please connect a camera.")
|
27 |
|
28 |
# arbitrary 3 maximum people are tracked. Maybe make it a parameter?
|
29 |
pose_landmarker_path: str = str(
|
30 |
+
files(reachy_mini_red_light_green_light).joinpath(
|
31 |
+
"pose_landmarker_full.task"
|
32 |
+
)
|
|
|
33 |
)
|
34 |
+
people_detector = PeopleDetector(model_path=pose_landmarker_path, max_poses=3)
|
35 |
|
36 |
def sequence():
|
37 |
time.sleep(1)
|
|
|
112 |
if len(buffer) > 0:
|
113 |
if time.time() - last_watched >= (scan_for / (len(buffer) + 2)):
|
114 |
print("LOOK")
|
|
|
115 |
selected_to_watch = np.random.randint(0, len(buffer))
|
116 |
left_shoulder = buffer[selected_to_watch][-1][0]
|
117 |
r_shoulder = buffer[selected_to_watch][-1][1]
|
|
|
119 |
(left_shoulder[0] + r_shoulder[0]) // 2,
|
120 |
(left_shoulder[1] + r_shoulder[1]) // 2,
|
121 |
)
|
122 |
+
reachy_mini.look_at_image(
|
123 |
+
look_at_px[0], look_at_px[1], duration=0.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
)
|
125 |
|
126 |
+
# normalized_look_at = (
|
127 |
+
# ((look_at_px[0] / frame.shape[1]) - 0.5) * 2,
|
128 |
+
# ((look_at_px[1] / frame.shape[0]) - 0.5) * 2,
|
129 |
+
# ) # Normalize to [-1, 1]
|
130 |
+
# yaw_range = [-80, 80]
|
131 |
+
# target_yaw = (
|
132 |
+
# normalized_look_at[0] * (yaw_range[1] - yaw_range[0]) / 2
|
133 |
+
# + (yaw_range[1] + yaw_range[0]) / 2
|
134 |
+
# )
|
135 |
+
# pose = create_head_pose(
|
136 |
+
# yaw=-target_yaw,
|
137 |
+
# )
|
138 |
+
# reachy_mini.goto_target(
|
139 |
+
# head=pose, antennas=[0.5, 0.0], duration=0.3
|
140 |
+
# )
|
141 |
+
|
142 |
last_watched = time.time()
|
143 |
buffer = []
|
144 |
moved = []
|