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
| import numpy as np from typing import Dict, List, Tuple from dataclasses import dataclass from enum import Enum
class SensorType(Enum): """传感器类型""" IR_CAMERA = "ir_camera" RGB_CAMERA = "rgb_camera" RADAR_60GHZ = "radar_60ghz" SEAT_SENSOR = "seat_sensor"
@dataclass class SensorData: """传感器数据""" sensor_type: SensorType timestamp: float data: np.ndarray metadata: Dict
class ValeoIMSFusion: """Valeo IMS多模态融合""" def __init__(self, config: Dict): """ 初始化融合系统 Args: config: 配置参数 """ self.config = config self.dms_module = DMSModule(config['dms']) self.oms_module = OMSModule(config['oms']) self.cpd_module = CPDModule(config['cpd']) self.fusion_weights = { 'dms': {'camera': 0.7, 'radar': 0.3}, 'oms': {'camera': 0.8, 'radar': 0.2}, 'cpd': {'radar': 0.6, 'camera': 0.4} } def process_frame(self, sensor_data: List[SensorData]) -> Dict: """ 处理单帧多传感器数据 Args: sensor_data: 传感器数据列表 Returns: result: 融合结果 """ preprocessed = self._preprocess_data(sensor_data) dms_result = self.dms_module.process( preprocessed.get(SensorType.IR_CAMERA) ) oms_result = self.oms_module.process( preprocessed.get(SensorType.RGB_CAMERA) ) cpd_result = self.cpd_module.process( preprocessed.get(SensorType.RADAR_60GHZ), preprocessed.get(SensorType.RGB_CAMERA) ) fused_result = self._fuse_results(dms_result, oms_result, cpd_result) return fused_result def _preprocess_data(self, sensor_data: List[SensorData]) -> Dict[SensorType, np.ndarray]: """预处理传感器数据""" preprocessed = {} for data in sensor_data: if data.sensor_type == SensorType.IR_CAMERA: preprocessed[data.sensor_type] = self._preprocess_ir(data.data) elif data.sensor_type == SensorType.RGB_CAMERA: preprocessed[data.sensor_type] = self._preprocess_rgb(data.data) elif data.sensor_type == SensorType.RADAR_60GHZ: preprocessed[data.sensor_type] = self._preprocess_radar(data.data) return preprocessed def _preprocess_ir(self, ir_image: np.ndarray) -> np.ndarray: """红外图像预处理""" ir_image = ir_image.astype(np.float32) / 255.0 return ir_image def _preprocess_rgb(self, rgb_image: np.ndarray) -> np.ndarray: """RGB图像预处理""" rgb_image = rgb_image.astype(np.float32) / 255.0 mean = np.array([0.485, 0.456, 0.406]) std = np.array([0.229, 0.224, 0.225]) rgb_image = (rgb_image - mean) / std return rgb_image def _preprocess_radar(self, radar_data: np.ndarray) -> np.ndarray: """雷达数据预处理""" return radar_data def _fuse_results(self, dms_result: Dict, oms_result: Dict, cpd_result: Dict) -> Dict: """融合多模块结果""" warnings = [] if dms_result.get('fatigue_level') != 'normal': warnings.append({ 'type': 'fatigue', 'level': dms_result['fatigue_level'], 'source': 'dms' }) if dms_result.get('is_distracted'): warnings.append({ 'type': 'distraction', 'source': 'dms' }) if oms_result.get('is_oop'): warnings.append({ 'type': 'oop', 'position': oms_result['position'], 'source': 'oms' }) if cpd_result.get('child_present'): warnings.append({ 'type': 'child_presence', 'location': cpd_result['location'], 'source': 'cpd' }) return { 'dms': dms_result, 'oms': oms_result, 'cpd': cpd_result, 'warnings': warnings }
class DMSModule: """驾驶员监测模块""" def __init__(self, config: Dict): self.config = config def process(self, ir_image: np.ndarray) -> Dict: """处理DMS""" return { 'fatigue_level': 'normal', 'is_distracted': False, 'gaze_direction': (0, 0) }
class OMSModule: """乘员监测模块""" def __init__(self, config: Dict): self.config = config def process(self, rgb_image: np.ndarray) -> Dict: """处理OMS""" return { 'occupants': 2, 'is_oop': False, 'position': 'normal' }
class CPDModule: """儿童存在检测模块""" def __init__(self, config: Dict): self.config = config def process(self, radar_data: np.ndarray, rgb_image: np.ndarray = None) -> Dict: """处理CPD""" return { 'child_present': False, 'location': None, 'vital_signs': None }
|