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
| """ Camera-in-the-Loop验证系统 适用于DMS/OMS摄像头验证 """
class CITLSystem: """ Camera-in-the-Loop验证系统 组件: 1. 仿真场景渲染器(Aurelion/Unreal Engine) 2. 高分辨率OLED显示屏 3. 物理IR/RGB摄像头 4. DMS/OMS算法 5. 评估框架 """ def __init__(self, config: dict): self.display = { 'type': 'OLED', 'resolution': config.get('display_res', (3840, 2160)), 'refresh_rate': config.get('display_fps', 120), 'brightness': config.get('brightness', 1000), 'contrast_ratio': '100000:1', 'response_time': '0.1ms', 'color_gamut': 'DCI-P3 98%' } self.camera = { 'sensor': config.get('sensor', 'AR0823AT'), 'resolution': (3840, 2160), 'fps': 60, 'lens': '6mm C-mount', 'ir_filter': '850nm bandpass', 'positioning': 'precision_6dof_stage' } self.scene_params = { 'driver_models': ['adult_male_1', 'adult_female_1', 'child_8yr', 'infant_rear_seat'], 'lighting': ['daylight_500lux', 'tunnel_transition', 'night_940nm_IR', 'dusk_50lux'], 'behaviors': ['normal_driving', 'phone_call', 'drowsy_eyelid_drop', 'looking_away_3s', 'yawning', 'head_drop'], 'environment': ['highway', 'urban', 'parking_lot'] } def run_scenario(self, scenario: dict) -> dict: """ 执行单个测试场景 Args: scenario: { 'driver': 'adult_male_1', 'behavior': 'drowsy_eyelid_drop', 'lighting': 'night_940nm_IR', 'environment': 'highway', 'duration_sec': 60, 'expected_detection': 'fatigue_F02', 'expected_max_latency_ms': 3000 } """ rendered_frames = self._render_scene(scenario) self._display_play(rendered_frames) captured_frames = self._camera_capture(len(rendered_frames)) detections = self._run_dms(captured_frames) result = self._evaluate(detections, scenario) return result def _render_scene(self, scenario): """渲染虚拟场景""" n_frames = scenario['duration_sec'] * self.camera['fps'] return [{'frame_id': i, 'data': f'rendered_{i}'} for i in range(n_frames)] def _display_play(self, frames): """显示屏播放""" pass def _camera_capture(self, n_frames): """物理摄像头采集""" return [{'frame_id': i, 'data': f'captured_{i}'} for i in range(n_frames)] def _run_dms(self, frames): """DMS算法处理""" return [{'frame_id': i, 'detection': 'fatigue', 'confidence': 0.92} for i in range(len(frames))] def _evaluate(self, detections, scenario): """评估检测结果""" expected = scenario['expected_detection'] detected = any(d['detection'] == expected for d in detections) latency = 250 return { 'scenario': f"{scenario['driver']}_{scenario['behavior']}_{scenario['lighting']}", 'expected': expected, 'detected': detected, 'latency_ms': latency, 'max_allowed_ms': scenario['expected_max_latency_ms'], 'pass': detected and latency <= scenario['expected_max_latency_ms'] } def batch_run(self, scenarios: list) -> dict: """ 批量执行场景 """ results = [] for s in scenarios: results.append(self.run_scenario(s)) pass_rate = sum(1 for r in results if r['pass']) / len(results) return { 'total': len(results), 'passed': sum(1 for r in results if r['pass']), 'failed': sum(1 for r in results if not r['pass']), 'pass_rate': pass_rate, 'results': results }
if __name__ == "__main__": citl = CITLSystem({ 'display_res': (3840, 2160), 'display_fps': 120, 'brightness': 1000, 'sensor': 'AR0823AT' }) euro_ncap_scenarios = [ {'driver': 'adult_male_1', 'behavior': 'drowsy_eyelid_drop', 'lighting': 'night_940nm_IR', 'environment': 'highway', 'duration_sec': 30, 'expected_detection': 'fatigue_F02', 'expected_max_latency_ms': 3000}, {'driver': 'adult_female_1', 'behavior': 'yawning', 'lighting': 'daylight_500lux', 'environment': 'urban', 'duration_sec': 30, 'expected_detection': 'fatigue_F04', 'expected_max_latency_ms': 3000}, {'driver': 'adult_male_1', 'behavior': 'phone_call', 'lighting': 'daylight_500lux', 'environment': 'highway', 'duration_sec': 30, 'expected_detection': 'distraction_D02', 'expected_max_latency_ms': 3000}, {'driver': 'adult_female_1', 'behavior': 'looking_away_3s', 'lighting': 'tunnel_transition', 'environment': 'highway', 'duration_sec': 30, 'expected_detection': 'distraction_D05', 'expected_max_latency_ms': 3000}, {'driver': 'adult_male_1', 'behavior': 'drowsy_eyelid_drop', 'lighting': 'night_940nm_IR', 'environment': 'urban', 'duration_sec': 30, 'expected_detection': 'fatigue_F02', 'expected_max_latency_ms': 3000}, {'driver': 'adult_female_1', 'behavior': 'head_drop', 'lighting': 'tunnel_transition', 'environment': 'highway', 'duration_sec': 30, 'expected_detection': 'fatigue_F03', 'expected_max_latency_ms': 3000}, ] results = citl.batch_run(euro_ncap_scenarios) print("=" * 60) print("CITL Euro NCAP DSM场景批量验证结果") print("=" * 60) print(f"总场景数: {results['total']}") print(f"通过: {results['passed']}") print(f"失败: {results['failed']}") print(f"通过率: {results['pass_rate']:.1%}") print("\n详细结果:") for r in results['results']: status = "✅ PASS" if r['pass'] else "❌ FAIL" print(f" {status} | {r['scenario']}") print(f" 检测: {r['detected']}, 延迟: {r['latency_ms']}ms")
|