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
| """ 座舱雷达+摄像头传感器融合系统 参考: Tesla/Murata/Magna 量产方案
融合策略: 决策级融合 (Late Fusion) - 摄像头: 驾驶员行为/表情/视线 - 雷达: 生命体征/存在检测/微动作 - 融合: 贝叶斯加权 + 冲突解决 """
import numpy as np from dataclasses import dataclass from typing import Optional, Dict, List from collections import deque
@dataclass class RadarOutput: """雷达感知输出""" presence_detected: bool num_occupants: int avg_heart_rate: float avg_breathing_rate: float movement_intensity: float position_estimate: tuple child_detected: bool
@dataclass class CameraOutput: """摄像头感知输出""" face_detected: bool eye_openness: float gaze_direction: tuple head_pose: tuple expression: str behavior: str confidence: float
@dataclass class FusedOutput: """融合输出""" occupant_present: bool occupant_category: str drowsiness_level: int distraction_level: int heart_rate: float breathing_rate: float position: tuple alerts: List[str]
class RadarCameraFusion: """ 雷达+摄像头决策级融合 融合规则: 1. 存在检测: 雷达为主(穿透遮挡), 摄像头为辅 2. 疲劳检测: 摄像头为主(面部), 雷达为辅(心率变异性) 3. CPD: 雷达为主(穿透), 摄像头辅助验证 4. 行为: 摄像头为主, 雷达运动强度辅助 """ def __init__(self): self.radar_weight_presence = 0.7 self.camera_weight_presence = 0.3 self.radar_weight_drowsiness = 0.3 self.camera_weight_drowsiness = 0.7 def fuse(self, radar: RadarOutput, camera: CameraOutput) -> FusedOutput: """执行融合""" occupant_present = self._fuse_presence(radar, camera) category = self._classify_occupant(radar, camera) drowsiness = self._fuse_drowsiness(radar, camera) distraction = self._assess_distraction(camera) hr = radar.avg_heart_rate if radar.avg_heart_rate > 0 else 0 br = radar.avg_breathing_rate if radar.avg_breathing_rate > 0 else 0 alerts = self._generate_alerts( drowsiness, distraction, category, radar ) return FusedOutput( occupant_present=occupant_present, occupant_category=category, drowsiness_level=drowsiness, distraction_level=distraction, heart_rate=hr, breathing_rate=br, position=radar.position_estimate, alerts=alerts ) def _fuse_presence(self, radar, camera): """存在检测融合""" if radar.presence_detected: return True if camera.face_detected: return True return False def _classify_occupant(self, radar, camera): """乘员分类""" if not radar.presence_detected and not camera.face_detected: return 'empty' if radar.child_detected: return 'child' if radar.movement_intensity < 0.1 and not camera.face_detected: return 'unknown_occupant' return 'adult' def _fuse_drowsiness(self, radar, camera): """疲劳融合 (0-3)""" cam_score = 0 if camera.eye_openness < 0.3: cam_score += 2 elif camera.eye_openness < 0.5: cam_score += 1 if camera.expression == 'tired': cam_score += 1 cam_score = min(cam_score, 3) radar_score = 0 if 50 < radar.avg_heart_rate < 60: radar_score += 1 if radar.avg_breathing_rate < 12: radar_score += 1 radar_score = min(radar_score, 3) fused = ( self.camera_weight_drowsiness * cam_score + self.radar_weight_drowsiness * radar_score ) return int(round(fused)) def _assess_distraction(self, camera): """分心评估""" if not camera.face_detected: return 0 if camera.behavior in ('phone', 'eating'): return 3 if abs(camera.gaze_direction[0]) > 30: return 2 if camera.behavior == 'distracted': return 2 return 0 def _generate_alerts(self, drowsiness, distraction, category, radar): """生成警报""" alerts = [] if drowsiness >= 2: alerts.append(f'疲劳警告(L{drowsiness})') if distraction >= 2: alerts.append(f'分心警告(L{distraction})') if category == 'child': alerts.append('儿童检测警报') if radar.avg_heart_rate > 120: alerts.append('心率异常') return alerts
if __name__ == "__main__": fusion = RadarCameraFusion() radar1 = RadarOutput( presence_detected=True, num_occupants=1, avg_heart_rate=72, avg_breathing_rate=16, movement_intensity=0.3, position_estimate=(0.5, 0.3, 1.2), child_detected=False ) cam1 = CameraOutput( face_detected=True, eye_openness=0.8, gaze_direction=(5, -5, 0), head_pose=(0, 0, 0), expression='neutral', behavior='driving', confidence=0.95 ) result1 = fusion.fuse(radar1, cam1) print("场景1: 正常驾驶") print(f" 乘员: {result1.occupant_category}") print(f" 疲劳: L{result1.drowsiness_level}") print(f" 分心: L{result1.distraction_level}") print(f" 心率: {result1.heart_rate} bpm") print(f" 警报: {result1.alerts}") radar2 = RadarOutput( presence_detected=True, num_occupants=1, avg_heart_rate=55, avg_breathing_rate=11, movement_intensity=0.05, position_estimate=(0.5, 0.3, 1.2), child_detected=False ) cam2 = CameraOutput( face_detected=True, eye_openness=0.15, gaze_direction=(0, 10, 0), head_pose=(5, 0, 0), expression='tired', behavior='driving', confidence=0.88 ) result2 = fusion.fuse(radar2, cam2) print("\n场景2: 疲劳驾驶") print(f" 乘员: {result2.occupant_category}") print(f" 疲劳: L{result2.drowsiness_level}") print(f" 心率: {result2.heart_rate} bpm (低)") print(f" 警报: {result2.alerts}") radar3 = RadarOutput( presence_detected=True, num_occupants=2, avg_heart_rate=90, avg_breathing_rate=22, movement_intensity=0.4, position_estimate=(1.2, 0.5, 0.8), child_detected=True ) cam3 = CameraOutput( face_detected=False, eye_openness=0, gaze_direction=(0, 0, 0), head_pose=(0, 0, 0), expression='neutral', behavior='driving', confidence=0.3 ) result3 = fusion.fuse(radar3, cam3) print("\n场景3: 后排儿童 (CPD)") print(f" 乘员: {result3.occupant_category}") print(f" 位置: {result3.position}") print(f" 警报: {result3.alerts}")
|