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
| """ OMS乘员监控系统 基于4D成像雷达的多功能检测 """
from dataclasses import dataclass from typing import List, Optional from enum import Enum
class OccupantType(Enum): """乘员类型""" ADULT = "adult" CHILD = "child" INFANT = "infant" PET = "pet" OBJECT = "object" EMPTY = "empty"
class SeatPosition(Enum): """座椅位置""" DRIVER = "driver" FRONT_PASSENGER = "front_passenger" REAR_LEFT = "rear_left" REAR_CENTER = "rear_center" REAR_RIGHT = "rear_right"
@dataclass class OccupantInfo: """乘员信息""" seat: SeatPosition type: OccupantType presence: bool position_3d: tuple vital_signs: Optional[dict] seatbelt_status: Optional[bool]
class OMSDetector: """ 乘员监控系统 功能: 1. 乘员分类(成人/儿童/婴儿座椅) 2. 位置检测 3. 生命体征监测 4. 安全带提醒增强 """ def __init__(self): self.size_thresholds = { 'adult': (0.3, 0.8), 'child': (0.15, 0.3), 'infant': (0.05, 0.15), 'pet': (0.02, 0.1), } def monitor_cabin(self, point_cloud: np.ndarray, vital_signs: np.ndarray) -> List[OccupantInfo]: """ 监控全车舱 Args: point_cloud: 3D点云 (N, 4) [x, y, z, intensity] vital_signs: 生命体征信号 Returns: 各座椅乘员信息 """ occupants = [] seat_regions = self._define_seat_regions() for seat, region in seat_regions.items(): seat_points = self._extract_region_points(point_cloud, region) if len(seat_points) < 10: occupants.append(OccupantInfo( seat=seat, type=OccupantType.EMPTY, presence=False, position_3d=(0, 0, 0), vital_signs=None, seatbelt_status=None )) continue volume = self._calculate_volume(seat_points) occupant_type = self._classify_occupant(volume, seat_points) position = self._calculate_position(seat_points) vitals = self._detect_vital_signs(vital_signs, region) occupants.append(OccupantInfo( seat=seat, type=occupant_type, presence=True, position_3d=position, vital_signs=vitals, seatbelt_status=None )) return occupants def _define_seat_regions(self) -> dict: """定义座椅3D区域""" return { SeatPosition.DRIVER: { 'x': (0.5, 1.2), 'y': (0.3, 0.8), 'z': (0.0, 1.0) }, SeatPosition.FRONT_PASSENGER: { 'x': (0.5, 1.2), 'y': (-0.8, -0.3), 'z': (0.0, 1.0) }, } def _extract_region_points(self, points: np.ndarray, region: dict) -> np.ndarray: """提取区域内的点""" mask = ( (points[:, 0] >= region['x'][0]) & (points[:, 0] <= region['x'][1]) & (points[:, 1] >= region['y'][0]) & (points[:, 1] <= region['y'][1]) & (points[:, 2] >= region['z'][0]) & (points[:, 2] <= region['z'][1]) ) return points[mask] def _calculate_volume(self, points: np.ndarray) -> float: """计算凸包体积""" x_range = points[:, 0].max() - points[:, 0].min() y_range = points[:, 1].max() - points[:, 1].min() z_range = points[:, 2].max() - points[:, 2].min() return x_range * y_range * z_range def _classify_occupant(self, volume: float, points: np.ndarray) -> OccupantType: """分类乘员类型""" for otype, (v_min, v_max) in self.size_thresholds.items(): if v_min <= volume < v_max: return OccupantType(otype) return OccupantType.OBJECT def _calculate_position(self, points: np.ndarray) -> tuple: """计算质心位置""" return tuple(points[:, :3].mean(axis=0)) def _detect_vital_signs(self, vital_signs: np.ndarray, region: dict) -> Optional[dict]: """检测生命体征""" return { 'breathing_rate': 18, 'heartbeat': 75 }
if __name__ == "__main__": detector = OMSDetector() np.random.seed(42) driver_points = np.random.randn(500, 4) driver_points[:, 0] = driver_points[:, 0] * 0.2 + 0.8 driver_points[:, 1] = driver_points[:, 1] * 0.2 + 0.5 driver_points[:, 2] = driver_points[:, 2] * 0.3 + 0.5 empty_points = np.random.randn(10, 4) * 0.01 point_cloud = np.vstack([driver_points, empty_points]) vital_signs = np.random.randn(100) occupants = detector.monitor_cabin(point_cloud, vital_signs) print("=== 乘员监控结果 ===") for occ in occupants: print(f"{occ.seat.value}: {occ.type.value}, 存在: {occ.presence}")
|