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
| import numpy as np from typing import Tuple, List, Optional from dataclasses import dataclass from enum import IntEnum
class AlertLevel(IntEnum): NORMAL = 0 VISUAL_HINT = 1 AR_GUIDE = 2 AUDIO_ALERT = 3 HAPTIC_ALERT = 4
@dataclass class GazePoint: x: float y: float timestamp: float confidence: float
@dataclass class RiskZone: """道路风险区域""" x: float y: float radius: float risk_type: str severity: int distance_m: float
class ARHUDAttentionGuide: """ AR-HUD 注意力引导系统 核心逻辑: 1. DMS 实时追踪注视点 2. 检测注意力偏离风险区域 3. 通过 AR-HUD 引导注意力回归 4. 闭环验证引导效果 基于 Frontiers 2025 AR-HUD 研究和 Aviation Today 2026 下一代 HUD 报告 """ def __init__(self, config: dict = None): config = config or {} self.gaze_history: List[GazePoint] = [] self.max_history = config.get('max_history', 150) self.deviation_threshold = config.get('deviation_threshold', 0.15) self.duration_threshold = config.get('duration_threshold', 2.0) self.current_guide_level = AlertLevel.NORMAL self.guide_start_time = None def update( self, gaze: GazePoint, risk_zones: List[RiskZone] ) -> dict: """ 每帧更新 Args: gaze: 当前注视点 risk_zones: 当前道路风险区域列表 Returns: guide_command: AR-HUD 引导指令 """ self.gaze_history.append(gaze) if len(self.gaze_history) > self.max_history: self.gaze_history.pop(0) attention_status = self._check_attention(gaze, risk_zones) if attention_status['deviated']: if self.guide_start_time is None: self.guide_start_time = gaze.timestamp duration = gaze.timestamp - self.guide_start_time if duration > self.duration_threshold * 3: level = AlertLevel.HAPTIC_ALERT elif duration > self.duration_threshold * 2: level = AlertLevel.AUDIO_ALERT elif duration > self.duration_threshold: level = AlertLevel.AR_GUIDE else: level = AlertLevel.VISUAL_HINT else: self.guide_start_time = None level = AlertLevel.NORMAL self.current_guide_level = level render_cmd = self._generate_render_command( level, gaze, risk_zones, attention_status ) return { 'alert_level': int(level), 'attention_status': attention_status, 'render_command': render_cmd } def _check_attention( self, gaze: GazePoint, risk_zones: List[RiskZone] ) -> dict: """检查注意力是否指向风险区域""" if not risk_zones: return {'deviated': False, 'nearest_risk_dist': float('inf')} distances = [] for zone in risk_zones: dist = np.sqrt( (gaze.x - zone.x)**2 + (gaze.y - zone.y)**2 ) distances.append((dist, zone)) distances.sort(key=lambda x: x[0]) nearest_dist, nearest_zone = distances[0] deviated = nearest_dist > self.deviation_threshold return { 'deviated': deviated, 'nearest_risk_dist': nearest_dist, 'nearest_risk_type': nearest_zone.risk_type, 'nearest_risk_severity': nearest_zone.severity, 'nearest_risk_distance_m': nearest_zone.distance_m } def _generate_render_command( self, level: AlertLevel, gaze: GazePoint, risk_zones: List[RiskZone], attention_status: dict ) -> dict: """生成 AR-HUD 渲染指令""" cmd = { 'mode': 'normal', 'elements': [] } if level == AlertLevel.NORMAL: cmd['mode'] = 'standard_info' elif level == AlertLevel.VISUAL_HINT: for zone in risk_zones: if zone.severity >= 2: cmd['elements'].append({ 'type': 'border_highlight', 'x': zone.x, 'y': zone.y, 'radius': zone.radius, 'color': 'yellow', 'blink': True, 'blink_rate': 2 }) cmd['mode'] = 'hint' elif level == AlertLevel.AR_GUIDE: for zone in risk_zones: if zone.severity >= 2: cmd['elements'].append({ 'type': 'arrow', 'from': {'x': gaze.x, 'y': gaze.y}, 'to': {'x': zone.x, 'y': zone.y}, 'color': 'orange', 'animated': True, 'label': zone.risk_type }) cmd['mode'] = 'guidance' elif level == AlertLevel.AUDIO_ALERT: for zone in risk_zones: cmd['elements'].append({ 'type': 'full_highlight', 'x': zone.x, 'y': zone.y, 'radius': zone.radius, 'color': 'red', 'pulse': True }) cmd['mode'] = 'warning' cmd['audio'] = True elif level == AlertLevel.HAPTIC_ALERT: cmd['mode'] = 'critical' cmd['audio'] = True cmd['haptic'] = True cmd['elements'].append({ 'type': 'fullscreen_flash', 'color': 'red' }) return cmd
if __name__ == "__main__": guide = ARHUDAttentionGuide() print("=== AR-HUD 注意力引导系统 ===") print(f"偏离阈值: {guide.deviation_threshold}") print(f"持续时间阈值: {guide.duration_threshold}s") risk_zones = [ RiskZone(0.5, 0.7, 0.1, 'pedestrian', 3, 30), RiskZone(0.8, 0.5, 0.08, 'vehicle_cut_in', 2, 50), ] gaze_normal = GazePoint(0.5, 0.65, 0.0, 0.95) result1 = guide.update(gaze_normal, risk_zones) print(f"\n场景1 (正常注视):") print(f" 告警等级: {result1['alert_level']}") print(f" 偏离: {result1['attention_status']['deviated']}") print(f" 模式: {result1['render_command']['mode']}") guide.guide_start_time = None for i in range(60): gaze_distracted = GazePoint(0.2, 0.3, i/30, 0.9) result2 = guide.update(gaze_distracted, risk_zones) print(f"\n场景2 (持续偏离2秒):") print(f" 告警等级: {result2['alert_level']}") print(f" 模式: {result2['render_command']['mode']}") print(f" 渲染元素数: {len(result2['render_command']['elements'])}") guide.guide_start_time = None for i in range(150): gaze_long = GazePoint(0.15, 0.25, i/30, 0.85) result3 = guide.update(gaze_long, risk_zones) print(f"\n场景3 (持续偏离5秒):") print(f" 告警等级: {result3['alert_level']}") print(f" 模式: {result3['render_command']['mode']}") print(f" 音频告警: {result3['render_command'].get('audio', False)}") print(f" 触觉告警: {result3['render_command'].get('haptic', False)}") print(f"\n=== 告警等级说明 ===") for level in AlertLevel: print(f" Level {level.value}: {level.name}")
|