-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
38 lines (28 loc) · 1.29 KB
/
Copy pathutils.py
File metadata and controls
38 lines (28 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# utils.py
# Helper functions for drawing and UDP command sending.
import socket, json, cv2
import numpy as np
ESP_HOST = ""
ESP_PORT = 0
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def send_cmd(v, omega):
msg = {"cmd": "drive", "v": float(v), "omega": float(omega)}
sock.sendto(json.dumps(msg).encode(), (ESP_HOST, ESP_PORT))
def send_stop():
sock.sendto(json.dumps({"cmd": "stop"}).encode(), (ESP_HOST, ESP_PORT))
# desc: Draws person box, depth mini-view, and current robot mode.
def draw_hud(frame, depth_map, box, mode, wall_cm):
disp = frame.copy()
if box is not None:
x1, y1, x2, y2 = map(int, (box["x1"], box["y1"], box["x2"], box["y2"]))
cv2.rectangle(disp, (x1, y1), (x2, y2), (0, 255, 0), 2)
h, w = disp.shape[:2]
overlay = disp.copy()
cv2.rectangle(overlay, (0, 0), (w, 40), (0, 0, 0), -1)
disp = cv2.addWeighted(overlay, 0.35, disp, 0.65, 0)
cv2.putText(disp, f"{mode} | range={wall_cm}", (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 255), 2)
depth_small = cv2.resize(depth_map, (w // 4, h // 4))
depth_vis = cv2.applyColorMap((depth_small * 255).astype(np.uint8), cv2.COLORMAP_INFERNO)
disp[0:depth_vis.shape[0], 0:depth_vis.shape[1]] = depth_vis
return disp