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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
| """ ZF 乘员分类算法
融合视觉 + 座椅压力 + 安全带传感器 """
import numpy as np from dataclasses import dataclass from typing import List, Dict, Tuple
@dataclass class OccupantState: """乘员状态""" body_type: str age_group: str posture: str oop_status: str seatbelt_status: str confidence: float
class ZFOccupantClassifier: """ ZF 乘员分类器 多传感器融合实现 """ def __init__(self): self.body_type_thresholds = { 'small': 40, 'medium': 70, 'large': 100 } self.posture_labels = ['normal', 'forward', 'left_lean', 'right_lean'] self.oop_angle_threshold = 30 def classify( self, camera_data: np.ndarray, pressure_map: np.ndarray, seatbelt_tension: float, seatbelt_buckle: bool, seat_position: Tuple[int, int] ) -> OccupantState: """ 综合分类 Args: camera_data: 座舱图像 (H, W, 3) pressure_map: 压力分布图 (H, W) seatbelt_tension: 安全带张力 N seatbelt_buckle: 安全带扣状态 seat_position: 座椅位置 (fore/aft, height) Returns: 乘员状态 """ body_type = self._estimate_body_type(pressure_map, seat_position) age_group = self._estimate_age(camera_data, body_type, seat_position) posture = self._estimate_posture(camera_data, pressure_map) oop_status = self._detect_oop(camera_data, posture, seatbelt_tension) seatbelt_status = self._check_seatbelt( camera_data, seatbelt_tension, seatbelt_buckle ) confidence = self._calculate_confidence( camera_data, pressure_map, seatbelt_tension ) return OccupantState( body_type=body_type, age_group=age_group, posture=posture, oop_status=oop_status, seatbelt_status=seatbelt_status, confidence=confidence ) def _estimate_body_type( self, pressure_map: np.ndarray, seat_position: Tuple[int, int] ) -> str: """ 估计体型 基于压力分布和座椅位置 """ total_pressure = np.sum(pressure_map) calibration_factor = 1.0 + (seat_position[0] - 50) / 100 estimated_weight = total_pressure * calibration_factor / 100 if estimated_weight < self.body_type_thresholds['small']: return 'small' elif estimated_weight < self.body_type_thresholds['medium']: return 'medium' else: return 'large' def _estimate_age( self, camera_data: np.ndarray, body_type: str, seat_position: Tuple[int, int] ) -> str: """ 估计年龄 基于视觉 + 座椅位置 """ visual_age_score = np.random.uniform(0, 1) seat_height = seat_position[1] if body_type == 'small' and seat_height > 70: return 'child' elif visual_age_score < 0.3: return 'child' else: return 'adult' def _estimate_posture( self, camera_data: np.ndarray, pressure_map: np.ndarray ) -> str: """ 估计坐姿 基于视觉关键点 + 压力分布 """ pressure_center = self._calculate_pressure_center(pressure_map) if pressure_center[0] < 0.4: return 'left_lean' elif pressure_center[0] > 0.6: return 'right_lean' elif pressure_center[1] < 0.4: return 'forward' else: return 'normal' def _detect_oop( self, camera_data: np.ndarray, posture: str, seatbelt_tension: float ) -> str: """ OOP 检测 异常姿态 + 安全带张力异常 """ if posture != 'normal': return 'oop' if seatbelt_tension < 2.0: return 'oop' return 'normal' def _check_seatbelt( self, camera_data: np.ndarray, seatbelt_tension: float, seatbelt_buckle: bool ) -> str: """ 检查安全带状态 检测误用场景 """ if not seatbelt_buckle: return 'unbuckled' if seatbelt_tension < 1.0: return 'misuse' return 'correct' def _calculate_pressure_center( self, pressure_map: np.ndarray ) -> Tuple[float, float]: """ 计算压力重心 """ total = np.sum(pressure_map) if total == 0: return (0.5, 0.5) y_coords, x_coords = np.meshgrid( np.arange(pressure_map.shape[0]), np.arange(pressure_map.shape[1]), indexing='ij' ) cx = np.sum(x_coords * pressure_map) / total / pressure_map.shape[1] cy = np.sum(y_coords * pressure_map) / total / pressure_map.shape[0] return (cx, cy) def _calculate_confidence( self, camera_data: np.ndarray, pressure_map: np.ndarray, seatbelt_tension: float ) -> float: """ 计算综合置信度 """ image_quality = 0.8 pressure_snr = np.max(pressure_map) / (np.std(pressure_map) + 1e-6) pressure_confidence = min(1.0, pressure_snr / 10) confidence = image_quality * 0.5 + pressure_confidence * 0.5 return confidence
class AdaptiveRestraintController: """ 自适应约束控制器 根据乘员状态调整安全带和气囊 """ def __init__(self): self.pretension_force = { 'small': 100, 'medium': 150, 'large': 200 } self.airbag_force = { 'child': 'low', 'adult_small': 'medium', 'adult_medium': 'medium', 'adult_large': 'high' } def get_restraint_config( self, occupant: OccupantState, crash_severity: str ) -> Dict: """ 获取约束配置 Args: occupant: 乘员状态 crash_severity: 碰撞严重程度 Returns: 约束配置 """ pretension = self.pretension_force[occupant.body_type] if crash_severity == 'high': pretension *= 1.5 elif crash_severity == 'low': pretension *= 0.8 if occupant.age_group == 'child': airbag_mode = 'suppressed' elif occupant.oop_status == 'oop': airbag_mode = 'low' else: key = f"adult_{occupant.body_type}" airbag_mode = self.airbag_force.get(key, 'medium') return { 'pretension_force': pretension, 'airbag_mode': airbag_mode, 'seatbelt_warning': occupant.seatbelt_status != 'correct', 'confidence': occupant.confidence }
if __name__ == "__main__": classifier = ZFOccupantClassifier() controller = AdaptiveRestraintController() camera_data = np.random.randint(0, 255, (720, 1280, 3), dtype=np.uint8) pressure_map = np.random.uniform(0, 100, (32, 32)) seatbelt_tension = 5.0 seatbelt_buckle = True seat_position = (60, 50) occupant = classifier.classify( camera_data, pressure_map, seatbelt_tension, seatbelt_buckle, seat_position ) print(f"乘员状态:") print(f" 体型: {occupant.body_type}") print(f" 年龄: {occupant.age_group}") print(f" 姿态: {occupant.posture}") print(f" OOP: {occupant.oop_status}") print(f" 安全带: {occupant.seatbelt_status}") print(f" 置信度: {occupant.confidence:.2f}") config = controller.get_restraint_config(occupant, 'medium') print(f"\n约束配置:") print(f" 预紧力: {config['pretension_force']:.1f} N") print(f" 气囊模式: {config['airbag_mode']}") print(f" 安全带警告: {config['seatbelt_warning']}")
|