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
| import numpy as np from dataclasses import dataclass from typing import Optional, Tuple
@dataclass class DriverAttentionState: """驾驶员注意力状态""" gaze_direction: Tuple[float, float] gaze_confidence: float distraction_level: int fatigue_level: int eyes_on_road: bool looking_at_hud: bool
class ARHUDAttentionGuidance: """ AR-HUD 注意力引导系统 ======================= 闭环架构: 1. DMS检测注意力状态 2. 判断是否需要引导 3. AR-HUD生成引导内容 4. 投影到驾驶员视野中 5. DMS验证引导效果 引导类型: - 视线召回: 分心时,箭头指向道路 - 危险高亮: 标注前方危险 - 路径引导: 导航路径叠加 - 疲劳提醒: 节奏变化的视觉提示 """ def __init__(self): self.gaze_recall_arrows = { "left": "←", "right": "→", "up": "↑", "center": "●" } def generate_guidance( self, attention: DriverAttentionState, vehicle_speed: float, forward_hazard: Optional[dict] = None, navigation: Optional[dict] = None ) -> dict: """ 生成AR-HUD引导内容 Args: attention: DMS提供的注意力状态 vehicle_speed: 车速 (km/h) forward_hazard: 前方危险信息 navigation: 导航信息 Returns: { 'display_mode': str, 'elements': list, 'priority': str, 'color': str, 'urgency': int # 0-3 } """ elements = [] urgency = 0 color = "white" if forward_hazard: elements.append({ 'type': 'hazard_highlight', 'position': forward_hazard.get('position', 'center'), 'shape': 'box', 'color': 'red', 'label': forward_hazard.get('type', 'Hazard') }) urgency = 3 color = "red" elif attention.distraction_level > 0: if not attention.eyes_on_road: az, el = attention.gaze_direction if abs(az) > 15: direction = "left" if az < 0 else "right" elements.append({ 'type': 'gaze_recall_arrow', 'symbol': self.gaze_recall_arrows[direction], 'color': 'amber' if attention.distraction_level == 1 else 'red', 'position': 'center_road' }) urgency = attention.distraction_level + 1 color = "amber" if urgency < 3 else "red" if attention.fatigue_level > 0: elements.append({ 'type': 'fatigue_alert', 'pattern': 'pulsing' if attention.fatigue_level == 1 else 'flashing', 'color': 'amber' if attention.fatigue_level == 1 else 'red', 'message': '建议休息' if attention.fatigue_level == 1 else '请立即停车休息' }) urgency = max(urgency, attention.fatigue_level + 1) if navigation and urgency < 2: elements.append({ 'type': 'navigation_path', 'path': navigation.get('path', []), 'color': 'blue', 'next_maneuver': navigation.get('next_maneuver') }) color = "blue" if urgency < 1: elements.append({ 'type': 'speed_display', 'value': vehicle_speed, 'limit': navigation.get('speed_limit') if navigation else None, 'color': 'white' }) if urgency >= 3: display_mode = "critical_alert" elif urgency >= 2: display_mode = "warning" elif urgency >= 1: display_mode = "caution" else: display_mode = "normal" return { 'display_mode': display_mode, 'elements': elements, 'priority': color, 'urgency': urgency }
if __name__ == "__main__": system = ARHUDAttentionGuidance() normal = DriverAttentionState( gaze_direction=(0, 0), gaze_confidence=0.95, distraction_level=0, fatigue_level=0, eyes_on_road=True, looking_at_hud=False ) result = system.generate_guidance(normal, vehicle_speed=80) print("场景1 (正常): {result['display_mode']}, {len(result['elements'])}个元素") distracted = DriverAttentionState( gaze_direction=(-30, -10), gaze_confidence=0.8, distraction_level=2, fatigue_level=0, eyes_on_road=False, looking_at_hud=False ) result = system.generate_guidance(distracted, vehicle_speed=80) print(f"场景2 (分心): {result['display_mode']}, urgency={result['urgency']}") for elem in result['elements']: print(f" - {elem['type']}: {elem}") hazard = { 'position': 'center_far', 'type': 'Pedestrian', 'distance': 50 } result = system.generate_guidance(normal, vehicle_speed=60, forward_hazard=hazard) print(f"\n场景3 (危险): {result['display_mode']}, urgency={result['urgency']}") for elem in result['elements']: print(f" - {elem['type']}: {elem}")
|