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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
| """ AR-HUD 驾驶员注意力引导系统
基于 DMS状态检测 + AR-HUD动态信息渲染 依赖: pip install numpy pygame(简单渲染)
核心原理: - DMS检测到注意力偏离 → AR-HUD在对应路面区域高亮 - 利用AR变焦特性,将信息投射到驾驶员自然视线区域 - 减少视线转移时间和频率 """
import numpy as np from typing import Dict, Tuple, List from dataclasses import dataclass from enum import IntEnum
class HUDPriority(IntEnum): BACKGROUND = 0 NAVIGATION = 1 SAFETY_ALERT = 2 CRITICAL_WARN = 3 EMERGENCY = 4
@dataclass class ARHUDElement: """AR-HUD显示元素""" element_id: str element_type: str priority: HUDPriority position_3d: Tuple[float, float, float] color: Tuple[int, int, int] opacity: float size: float duration_ms: int animation: str = ""
class ARHUDAttentionGuide: """ AR-HUD注意力引导引擎 输入: DMS状态 + ADAS状态 + 导航状态 输出: AR-HUD渲染元素列表(按优先级排序) """ def __init__(self, display_range_m: float = 15.0): self.display_range = display_range_m self.active_elements = [] def on_distracted(self, gaze_off_road_sec: float, gaze_direction: Tuple[float, float]) -> List[ARHUDElement]: """ 分心时注意力引导 策略: 1. 在驾驶员视线方向高亮路面关键区域 2. 显示箭头指向前方 3. 如果持续,升级为图标警告 """ elements = [] if gaze_off_road_sec > 2.0: elements.append(ARHUDElement( element_id='road_highlight', element_type='highlight', priority=HUDPriority.SAFETY_ALERT, position_3d=(0, 0, 15), color=(100, 255, 100), opacity=0.3, size=8.0, duration_ms=2000, animation='pulse' )) elements.append(ARHUDElement( element_id='attention_arrow', element_type='arrow', priority=HUDPriority.SAFETY_ALERT, position_3d=(0, -1, 10), color=(255, 255, 0), opacity=0.8, size=5.0, duration_ms=2000, animation='pulse' )) if gaze_off_road_sec > 4.0: elements.append(ARHUDElement( element_id='distraction_warning', element_type='icon', priority=HUDPriority.CRITICAL_WARN, position_3d=(0, 0, 8), color=(255, 100, 100), opacity=0.9, size=4.0, duration_ms=3000, animation='expand' )) return elements def on_fatigue(self, perclos: float, next_rest_stop_km: float = 50) -> List[ARHUDElement]: """ 疲劳时的AR-HUD引导 """ elements = [] if perclos > 0.15: elements.append(ARHUDElement( element_id='fatigue_coffee', element_type='icon', priority=HUDPriority.SAFETY_ALERT, position_3d=(-3, 0, 5), color=(255, 200, 100), opacity=0.7, size=3.0, duration_ms=5000, animation='pulse' )) elements.append(ARHUDElement( element_id='rest_distance', element_type='text', priority=HUDPriority.SAFETY_ALERT, position_3d=(-3, -1, 5), color=(255, 255, 255), opacity=0.8, size=2.0, duration_ms=5000, animation='fade' )) if perclos > 0.30: elements.append(ARHUDElement( element_id='fatigue_critical', element_type='icon', priority=HUDPriority.CRITICAL_WARN, position_3d=(0, 0, 6), color=(255, 50, 50), opacity=1.0, size=6.0, duration_ms=10000, animation='expand' )) return elements def on_phone_use(self, phone_position: str) -> List[ARHUDElement]: """手机使用警告""" elements = [] if phone_position in ['ear', 'texting']: elements.append(ARHUDElement( element_id='phone_warning', element_type='icon', priority=HUDPriority.CRITICAL_WARN, position_3d=(0, 0, 7), color=(255, 50, 50), opacity=1.0, size=5.0, duration_ms=3000, animation='pulse' )) elements.append(ARHUDElement( element_id='road_highlight_phone', element_type='highlight', priority=HUDPriority.SAFETY_ALERT, position_3d=(0, 0, 15), color=(255, 100, 100), opacity=0.4, size=10.0, duration_ms=3000, animation='pulse' )) return elements def on_forward_collision(self, ttc_sec: float, vehicle_distance: float) -> List[ARHUDElement]: """ 前向碰撞警告 Args: ttc_sec: 碰撞倒计时(秒) vehicle_distance: 前车距离(米) """ elements = [] if ttc_sec < 3.0: elements.append(ARHUDElement( element_id='fcw_box', element_type='box', priority=HUDPriority.EMERGENCY, position_3d=(0, 0, vehicle_distance), color=(255, 0, 0), opacity=1.0, size=5.0, duration_ms=int(ttc_sec * 1000), animation='expand' )) elements.append(ARHUDElement( element_id='fcw_flash', element_type='highlight', priority=HUDPriority.EMERGENCY, position_3d=(0, 0, vehicle_distance + 2), color=(255, 0, 0), opacity=1.0, size=8.0, duration_ms=500, animation='pulse' )) return elements def on_navigation(self, turn_direction: str, turn_distance_m: float) -> List[ARHUDElement]: """导航引导""" elements = [] if turn_distance_m < 500: arrow_pos = (0, -1, max(turn_distance_m, 5)) elements.append(ARHUDElement( element_id='nav_arrow', element_type='arrow', priority=HUDPriority.NAVIGATION, position_3d=arrow_pos, color=(0, 255, 255), opacity=0.8, size=4.0, duration_ms=10000, animation='static' )) return elements def compose_display(self, *element_lists) -> List[ARHUDElement]: """ 组合所有元素并按优先级排序 """ all_elements = [] for lst in element_lists: all_elements.extend(lst) all_elements.sort(key=lambda e: -int(e.priority)) return all_elements[:8]
if __name__ == "__main__": guide = ARHUDAttentionGuide() print("=== 分心引导 ===") distract_elems = guide.on_distracted(3.5, (0.3, 0.1)) for e in distract_elems: print(f" {e.element_id}: {e.element_type}, " f"优先级={e.priority}, 动画={e.animation}") print(f"\n=== 疲劳引导 ===") fatigue_elems = guide.on_fatigue(0.28, next_rest_stop_km=35) for e in fatigue_elems: print(f" {e.element_id}: {e.element_type}, " f"优先级={e.priority}") print(f"\n=== 手机使用警告 ===") phone_elems = guide.on_phone_use('texting') for e in phone_elems: print(f" {e.element_id}: {e.element_type}, " f"优先级={e.priority}") print(f"\n=== 碰撞警告 ===") collision_elems = guide.on_forward_collision(2.5, 25.0) for e in collision_elems: print(f" {e.element_id}: {e.element_type}, " f"优先级={e.priority}") print(f"\n=== 组合显示 ===") display = guide.compose_display( distract_elems, fatigue_elems, phone_elems, collision_elems ) for e in display: print(f" [{e.priority}] {e.element_id}: {e.element_type}")
|