add:倒车辅助线

This commit is contained in:
2026-04-07 14:11:33 +08:00
parent fc4b56776b
commit 04561d2697
5 changed files with 74 additions and 19 deletions

Binary file not shown.

View File

@@ -10,5 +10,5 @@ do
echo kill${pid}
kill -9 $pid
echo kill${pid}success
sleep 1
sleep 0.1
done

View File

@@ -1,8 +1,8 @@
{
"carousel_interval": 4,
"brightness": 50,
"radar_unit": 1,
"radar_unit": 0,
"show_radar": 1,
"radar_alarm_dist": 5,
"radar_alarm_dist": 15,
"display_mode": 0
}

87
web.py
View File

@@ -228,7 +228,7 @@ class SerialWorker(threading.Thread):
def _parse_rx_frame(self, frame):
# print("[串口1 RX] " + " ".join("{:02X}".format(b) for b in frame))
if len(frame) != 10 or frame[0] != 0x55 or frame[9] != 0xAA:
return
front = frame[1]; left = frame[2]
@@ -266,7 +266,6 @@ class SerialWorker(threading.Thread):
while self.running:
try:
frame = self._build_tx_frame()
print("[串口1 TX] " + " ".join("{:02X}".format(b) for b in frame))
ser.write(frame)
except Exception as e:
if self.running:
@@ -331,7 +330,6 @@ class RemoteWorker(threading.Thread):
if frame[:7] != REMOTE_HEADER:
return
code = frame[7]
print("[遥控] 0x{:02X}".format(code))
self.signals.key_pressed.emit(code)
if code == KEY_OK:
self.signals.enter_settings.emit()
@@ -822,6 +820,71 @@ class RenderWorker(threading.Thread):
else:
back_part = np.zeros((sh, fw, 3), dtype=np.uint8)
# --------------------------
# 新增:绘制红/黄/绿倒车辅助线
# --------------------------
if back_frame is not None:
h, w = back_part.shape[:2]
h=h//2 # 只在下半部分绘制辅助线
# ==========================================
# 倒车线参数 - 梯形向远方伸长版本
# ==========================================
# 底部(车尾)两个端点 - 宽
bottom_left = (int(w * 0.10), h+h) # 左侧起始10%
bottom_right = (int(w * 0.90), h+h) # 右侧结束90%
# 顶部(远方)- 更窄,形成更强的透视感
# 绿色(最远,安全区)- 伸长到更高更窄的位置
green_top_left = (int(w * 0.35), int(h * 0.12+h)) # 更窄更远
green_top_right = (int(w * 0.65), int(h * 0.12+h))
# 黄色(中间,警示区)
yellow_top_left = (int(w * 0.28), int(h * 0.35+h)) # 稍宽
yellow_top_right = (int(w * 0.72), int(h * 0.35+h))
# 红色(最近,危险区)
red_top_left = (int(w * 0.21), int(h * 0.60+h)) # 更宽
red_top_right = (int(w * 0.79), int(h * 0.60+h))
# 颜色定义BGR格式
color_green = (0, 0, 255) # 绿色
color_red = (0, 255, 255) # 黄色
color_yellow = (0, 255, 0) # 红色
# 绘制梯形(填充半透明)
overlay = back_part.copy()
alpha = 0.2 # 透明度
# 绘制绿色区域(最远,安全区)
green_pts = np.array([bottom_left, green_top_left, green_top_right, bottom_right], np.int32)
cv2.fillPoly(overlay, [green_pts], color_green)
# 绘制黄色区域(中间,警示区)
yellow_pts = np.array([green_top_left, yellow_top_left, yellow_top_right, green_top_right], np.int32)
cv2.fillPoly(overlay, [yellow_pts], color_yellow)
# 绘制红色区域(最近,危险区)
red_pts = np.array([yellow_top_left, red_top_left, red_top_right, yellow_top_right], np.int32)
cv2.fillPoly(overlay, [red_pts], color_red)
# 绘制左右车道线(加强透视感)
# 左线
cv2.line(overlay, bottom_left, green_top_left, (255, 255, 255), 2)
# 右线
cv2.line(overlay, bottom_right, green_top_right, (255, 255, 255), 2)
# 混合半透明效果
back_part = cv2.addWeighted(overlay, alpha, back_part, 1 - alpha, 0)
# --------------------------
# 原有亮度调节逻辑(保留)
# --------------------------
if brightness != 50:
alpha_v = brightness / 50.0
back_part = cv2.convertScaleAbs(back_part, alpha=alpha_v, beta=0)
@@ -842,19 +905,18 @@ class RenderWorker(threading.Thread):
else radar_dist)
alarm_d = cfg.get("radar_alarm_dist", 50)
rc = ((255, 80, 80) if dist_val <= alarm_d else (180, 220, 255))
texts.append((bw + 10, sh - 80,
texts.append((bw + 10, 48,
f"雷达: {dist_val} {unit_str} 报警值: {alarm_d}{unit_str}",
rc, 22))
rc, 26))
# 停机状态
stop_text = "已停机" if is_stopped else "运行中"
stop_color = ((255, 100, 100) if is_stopped else (100, 255, 100))
texts.append((bw + 10, sh - 52, f"状态: {stop_text}", stop_color, 22))
texts.append((bw + 500, 20, f"状态: {stop_text}", stop_color, 30))
# 时间戳
texts.append((bw + 10, sh - 26,
time.strftime("%Y-%m-%d %H:%M:%S"), (160, 160, 160), 20))
# texts.append((bw + 10, sh - 26,
# time.strftime("%Y-%m-%d %H:%M:%S"), (160, 160, 160), 20))
elif display_mode == "fullscreen":
# ==========================================
# 全屏轮播模式:显示有人方向的画面
@@ -1023,13 +1085,6 @@ class RenderWorker(threading.Thread):
presence[0], presence[1], presence[2], presence[3],
radar_thr)
# 记录状态用于调试
if self._last_active_dirs != active_dirs:
self._last_active_dirs = active_dirs.copy()
mode_str = {"reverse": "倒车模式", "fullscreen": "全屏轮播",
"normal": "正常模式"}.get(display_mode, display_mode)
print(f"[RENDER] 模式切换: {mode_str}, 检测到: {active_dirs}, 倒车: {is_reverse}")
except Exception as e:
print("[RENDER ERROR] {}".format(e))