lucasfiotti commited on
Commit
ef0438c
·
1 Parent(s): 435618a

Code pour le jalon 3

Browse files
Files changed (2) hide show
  1. coquille/Jalon2OPTI.py +1 -1
  2. coquille/Jalon3.py +96 -0
coquille/Jalon2OPTI.py CHANGED
@@ -157,7 +157,7 @@ while True:
157
  h, w, _ = frame.shape # Extrait les dimensions de l'image
158
 
159
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Convertit l'image BGR en RGB
160
- mp_image = Image(image_format=ImageFormat.SRGB, data=rgb_frame) # Englobe le tableau numpy dans un objet Iage Mediapipe
161
 
162
  timestamp_ms = int(timestamp * 1000)
163
  results = detector.detect_for_video(mp_image, timestamp_ms) # Detection des landmarks
 
157
  h, w, _ = frame.shape # Extrait les dimensions de l'image
158
 
159
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Convertit l'image BGR en RGB
160
+ mp_image = Image(image_format=ImageFormat.SRGB, data=rgb_frame) # Englobe le tableau numpy dans un objet Image Mediapipe
161
 
162
  timestamp_ms = int(timestamp * 1000)
163
  results = detector.detect_for_video(mp_image, timestamp_ms) # Detection des landmarks
coquille/Jalon3.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import threading
2
+ from reachy_mini import ReachyMini, ReachyMiniApp
3
+ from reachy_mini.utils import create_head_pose
4
+ import numpy as np
5
+ import time
6
+ from pydantic import BaseModel
7
+ import csv
8
+
9
+
10
+ class Test(ReachyMiniApp):
11
+ # Optional: URL to a custom configuration page for the app
12
+ # eg. "http://localhost:8042"
13
+ custom_app_url: str | None = "http://0.0.0.0:8042"
14
+ # Optional: specify a media backend ("gstreamer", "gstreamer_no_video", "default", etc.)
15
+ # On the wireless, use gstreamer_no_video to optimise CPU usage if the app does not use video streaming
16
+ request_media_backend: str | None = None
17
+
18
+ def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
19
+ t0 = time.time()
20
+
21
+ antennas_enabled = True
22
+ sound_play_requested = False
23
+
24
+ # You can ignore this part if you don't want to add settings to your app. If you set custom_app_url to None, you have to remove this part as well.
25
+ # === vvv ===
26
+ class AntennaState(BaseModel):
27
+ enabled: bool
28
+
29
+ @self.settings_app.post("/antennas")
30
+ def update_antennas_state(state: AntennaState):
31
+ nonlocal antennas_enabled
32
+ antennas_enabled = state.enabled
33
+ return {"antennas_enabled": antennas_enabled}
34
+
35
+ @self.settings_app.post("/play_sound")
36
+ def request_sound_play():
37
+ nonlocal sound_play_requested
38
+ sound_play_requested = True
39
+
40
+ # === ^^^ ===
41
+
42
+ # Main control loop
43
+ while not stop_event.is_set():
44
+ with open('resultats.csv', newline='') as csvfile:
45
+ reader = csv.DictReader(csvfile)
46
+ rows = list(reader)
47
+
48
+ val_bouche = [float(r["bouche"]) for r in rows]
49
+ bouche_min = min(val_bouche)
50
+ bouche_max = max(val_bouche)
51
+
52
+ val_norm_x = [float(r["norm_x"]) for r in rows]
53
+ norm_x_min = min(val_norm_x)
54
+ norm_x_max = max(val_norm_x)
55
+
56
+ val_norm_y = [float(r["norm_y"]) for r in rows]
57
+ norm_y_min = min(val_norm_y)
58
+ norm_y_max = max(val_norm_y)
59
+
60
+ val_oeil_g = [float(r["oeil_g"]) for r in rows]
61
+ oeil_g_min = min(val_oeil_g)
62
+ oeil_g_max = max(val_oeil_g)
63
+
64
+ val_oeil_d = [float(r["oeil_d"]) for r in rows]
65
+ oeil_d_min = min(val_oeil_d)
66
+ oeil_d_max = max(val_oeil_d)
67
+
68
+ last_timestamp = 0
69
+ for row in rows:
70
+ x_pos = ((float(row["bouche"]) - bouche_min) / (bouche_max - bouche_min))*0.02-0.01
71
+ y_pos = ((float(row["norm_x"]) - norm_x_min) / (norm_x_max - norm_x_min))*0.06-0.03
72
+ z_pos = ((float(row["norm_y"]) - norm_y_min) / (norm_y_max - norm_y_min))*0.015-0.0075
73
+ pitch_deg = ((float(row["pitch"])+180) % 360)
74
+ yaw_deg = float(row["yaw"])
75
+ roll_deg = float(row["roll"])
76
+ if antennas_enabled:
77
+ amp_deg = 50.0
78
+ g = ((float(row["oeil_g"]) - oeil_g_min) / (oeil_g_max - oeil_g_min))*amp_deg
79
+ d = ((float(row["oeil_d"]) - oeil_d_min) / (oeil_d_max - oeil_d_min)) * amp_deg
80
+ antennas_deg = np.array([-g, d])
81
+ else:
82
+ antennas_deg = np.array([0.0, 0.0])
83
+ antennas_rad = np.deg2rad(antennas_deg)
84
+ head_pose = create_head_pose(x=x_pos, y=y_pos, z=z_pos, pitch = pitch_deg, yaw = -yaw_deg, roll = roll_deg)
85
+ reachy_mini.set_target(head=head_pose, antennas=antennas_rad)
86
+ print(row["timestamp"])
87
+ time.sleep(float(row['timestamp']) - last_timestamp)
88
+ last_timestamp = float(row['timestamp'])
89
+
90
+
91
+ if __name__ == "__main__":
92
+ app = Test()
93
+ try:
94
+ app.wrapped_run()
95
+ except KeyboardInterrupt:
96
+ app.stop()