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
| """ Aptiv 风格座舱合成数据生成框架 """
import numpy as np from dataclasses import dataclass from typing import List, Optional import json
@dataclass class CabinOccupant: """乘员参数""" age: int height_cm: float weight_kg: float gender: str seat_position: str posture: str clothing: str belt_status: str 遮挡: str
@dataclass class CabinEnvironment: """座舱环境参数""" illumination_lux: float ir_active: bool time_of_day: str temperature_c: float humidity_pct: float
@dataclass class SyntheticScenario: """合成场景定义""" scenario_id: str occupants: List[CabinOccupant] environment: CabinEnvironment camera_config: dict expected_detection: dict
class SyntheticDataGenerator: """ 座舱合成数据生成器 生成 Euro NCAP 虚拟评估所需的场景数据 """ DSM_SCENARIOS = { 'D-01': '驾驶员视线直视前方', 'D-02': '驾驶员手持手机至耳边', 'D-03': '驾驶员低头看手机/打字', 'D-04': '驾驶员与乘客交谈(视线偏移)', 'D-05': '视线偏离道路 >3秒', 'F-01': 'PERCLOS >= 30% 持续5秒', 'F-02': '微睡眠(闭眼1.5秒)', 'F-03': '频繁打哈欠', } OMS_SCENARIOS = { 'O-01': '前排正常坐姿成人', 'O-02': '后排儿童座椅', 'O-03': '后排儿童(无座椅)', 'O-04': '空座', 'O-05': '安全带误用 - 腋下', 'O-06': '安全带误用 - 背后', 'CPD-01': '后座遗留婴儿(睡眠)', 'CPD-02': '毛毯覆盖儿童', 'CPD-03': '儿童座椅遮挡', } def __init__(self): self.occupant_templates = self._init_occupant_templates() self.environment_templates = self._init_environment_templates() def _init_occupant_templates(self) -> List[CabinOccupant]: """初始化乘员模板""" templates = [] templates.append(CabinOccupant(35, 175, 75, 'male', 'driver', 'upright', 'light', 'correct', 'none')) templates.append(CabinOccupant(30, 162, 55, 'female', 'front_passenger', 'upright', 'dark', 'correct', 'none')) templates.append(CabinOccupant(3, 95, 15, 'child', 'rear_left', 'upright', 'light', 'correct', 'child_seat')) templates.append(CabinOccupant(0, 65, 7, 'child', 'rear_right', 'upright', 'light', 'correct', 'child_seat')) templates.append(CabinOccupant(40, 180, 80, 'male', 'driver', 'leaning_forward', 'dark', 'correct', 'none')) templates.append(CabinOccupant(25, 170, 65, 'female', 'driver', 'upright', 'light', 'under_arm', 'none')) templates.append(CabinOccupant(2, 85, 12, 'child', 'rear_middle', 'upright', 'light', 'correct', 'blanket')) templates.append(CabinOccupant(0, 0, 0, 'child', 'rear_middle', 'upright', 'light', 'unfastened', 'none')) return templates def _init_environment_templates(self) -> List[CabinEnvironment]: """初始化环境模板""" return [ CabinEnvironment(500, True, 'day', 22, 45), CabinEnvironment(50, True, 'dusk', 18, 50), CabinEnvironment(5, True, 'night', 15, 55), CabinEnvironment(100, True, 'tunnel', 20, 60), ] def generate_scenario_matrix(self) -> List[SyntheticScenario]: """生成全场景矩阵""" scenarios = [] for occ in self.occupant_templates: for env in self.environment_templates: for scenario_id, desc in {**self.DSM_SCENARIOS, **self.OMS_SCENARIOS}.items(): scenario = SyntheticScenario( scenario_id=f"{scenario_id}_{occ.gender}_{env.time_of_day}", occupants=[occ], environment=env, camera_config={ 'resolution': (1600, 1200), 'fps': 30, 'ir_wavelength_nm': 940, 'fov_deg': 120, }, expected_detection=self._get_expected_detection(scenario_id, occ) ) scenarios.append(scenario) return scenarios def _get_expected_detection(self, scenario_id: str, occ: CabinOccupant) -> dict: """根据场景和乘员生成预期检测结果""" if occ.weight_kg == 0: return {'occupant_present': False, 'classification': 'empty'} if scenario_id.startswith('CPD'): return { 'occupant_present': True, 'classification': 'child' if occ.age <= 3 else 'adult', 'belt_status': occ.belt_status, 'posture': occ.posture, 'occlusion': occ.遮挡 } if scenario_id.startswith('F'): return { 'drowsiness_level': 'fatigued', 'perclos': 0.3 if 'F-01' in scenario_id else 0.15, } if scenario_id.startswith('D'): return { 'distraction_level': 'distracted' if 'D-02' in scenario_id or 'D-03' in scenario_id else 'normal', 'gaze_direction': 'away' if 'D-02' in scenario_id or 'D-05' in scenario_id else 'forward', } return {'occupant_present': True, 'classification': 'unknown'}
if __name__ == "__main__": generator = SyntheticDataGenerator() scenarios = generator.generate_scenario_matrix() print(f"生成场景总数: {len(scenarios)}") dsm_count = sum(1 for s in scenarios if s.scenario_id.startswith('D') or s.scenario_id.startswith('F')) oms_count = sum(1 for s in scenarios if s.scenario_id.startswith('O')) cpd_count = sum(1 for s in scenarios if s.scenario_id.startswith('CPD')) print(f" DSM 场景: {dsm_count}") print(f" OMS 场景: {oms_count}") print(f" CPD 场景: {cpd_count}") example = scenarios[0] print(f"\n示例场景: {example.scenario_id}") print(f" 乘员: {example.occupants[0].gender}, {example.occupants[0].age}岁") print(f" 环境: {example.environment.time_of_day}, {example.environment.illumination_lux}lux") print(f" 预期: {example.expected_detection}")
|