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
| """ OCS乘员分类系统 """
import numpy as np from enum import Enum from dataclasses import dataclass from typing import Optional, Tuple
class OccupantClass(Enum): """乘员分类""" EMPTY = "empty" REAR_FACING_CHILD_SEAT = "rfcs" FORWARD_FACING_CHILD_SEAT = "ffcs" CHILD = "child" SMALL_ADULT = "small_adult" ADULT = "adult" UNKNOWN = "unknown"
class AirbagMode(Enum): """气囊模式""" DISABLED = "disabled" LOW_POWER = "low_power" NORMAL = "normal" HIGH_POWER = "high_power"
@dataclass class PressureMap: """压力分布图""" data: np.ndarray total_weight: float center_of_pressure: Tuple[float, float]
class OccupantClassificationSystem: """ 乘员分类系统 功能: 1. 基于压力传感垫分析乘员特征 2. 结合摄像头进行多模态融合 3. 输出分类结果和气囊控制信号 """ def __init__(self): self.weight_thresholds = { 'empty': 5, 'rfcs': 15, 'ffcs': 15, 'child': 50, 'small_adult': 75, } self.pressure_features = { 'rfcs_pattern': 0.7, 'ffcs_pattern': 0.6, } def classify(self, pressure_map: PressureMap, camera_detection: Optional[dict] = None) -> OccupantClass: """ 分类乘员 Args: pressure_map: 压力分布图 camera_detection: 摄像头检测结果(可选) Returns: 乘员分类 """ weight = pressure_map.total_weight if weight < self.weight_thresholds['empty']: return OccupantClass.EMPTY pressure_features = self._extract_pressure_features(pressure_map) if pressure_features['concentration'] > self.pressure_features['rfcs_pattern']: if camera_detection: if camera_detection.get('child_seat_detected'): if camera_detection.get('rear_facing'): return OccupantClass.REAR_FACING_CHILD_SEAT else: return OccupantClass.FORWARD_FACING_CHILD_SEAT else: return OccupantClass.REAR_FACING_CHILD_SEAT if weight < self.weight_thresholds['child']: return OccupantClass.CHILD elif weight < self.weight_thresholds['small_adult']: return OccupantClass.SMALL_ADULT else: return OccupantClass.ADULT def get_airbag_mode(self, occupant_class: OccupantClass, crash_severity: str = 'moderate') -> AirbagMode: """ 获取气囊部署模式 Args: occupant_class: 乘员分类 crash_severity: 碰撞严重程度 Returns: 气囊模式 """ disable_conditions = [ OccupantClass.EMPTY, OccupantClass.REAR_FACING_CHILD_SEAT, ] if occupant_class in disable_conditions: return AirbagMode.DISABLED if occupant_class == OccupantClass.FORWARD_FACING_CHILD_SEAT: return AirbagMode.DISABLED elif occupant_class == OccupantClass.CHILD: return AirbagMode.LOW_POWER elif occupant_class == OccupantClass.SMALL_ADULT: if crash_severity == 'low': return AirbagMode.LOW_POWER else: return AirbagMode.NORMAL else: if crash_severity == 'high': return AirbagMode.HIGH_POWER else: return AirbagMode.NORMAL def _extract_pressure_features(self, pressure_map: PressureMap) -> dict: """提取压力分布特征""" data = pressure_map.data threshold = np.max(data) * 0.5 high_pressure_ratio = np.sum(data > threshold) / data.size uniformity = 1 - np.std(data) / (np.mean(data) + 1e-8) from scipy import ndimage labeled, num_features = ndimage.label(data > threshold) return { 'concentration': high_pressure_ratio, 'uniformity': uniformity, 'num_regions': num_features, }
if __name__ == "__main__": ocs = OccupantClassificationSystem() print("=== 乘员分类测试 ===") pressure = PressureMap( data=np.random.randn(32, 32) * 0.1, total_weight=2.0, center_of_pressure=(16, 16) ) result = ocs.classify(pressure) mode = ocs.get_airbag_mode(result) print(f"空座: 分类={result.value}, 气囊模式={mode.value}") data = np.zeros((32, 32)) data[10:22, 10:22] = 1.0 pressure = PressureMap( data=data, total_weight=12.0, center_of_pressure=(16, 16) ) result = ocs.classify(pressure, {'child_seat_detected': True, 'rear_facing': True}) mode = ocs.get_airbag_mode(result) print(f"后向儿童座椅: 分类={result.value}, 气囊模式={mode.value}") data = np.random.randn(32, 32) * 0.3 + 0.5 pressure = PressureMap( data=data, total_weight=75.0, center_of_pressure=(16, 16) ) result = ocs.classify(pressure) mode = ocs.get_airbag_mode(result) print(f"成人: 分类={result.value}, 气囊模式={mode.value}")
|