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
| class OOPDetector: """OOP(异常姿态)检测器""" def __init__(self, vehicle_config: Dict): """ Args: vehicle_config: 车辆配置(座椅位置、安全气囊位置等) """ self.config = vehicle_config self.thresholds = { 'forward_lean': 0.3, 'side_lean': 0.2, 'recline_angle': 30, } def detect_oop(self, pose: np.ndarray, seat_position: str) -> Dict: """ 检测OOP Args: pose: (16, 3) 乘员姿态 seat_position: 座位位置('driver', 'passenger', 'rear_left', 'rear_right') Returns: oop_result: OOP检测结果 """ oop_types = [] if self._detect_forward_lean(pose): oop_types.append({ 'type': 'forward_lean', 'severity': 'high', 'description': '乘员前倾,靠近仪表盘/方向盘', 'action': '禁用/调整前排安全气囊' }) if self._detect_side_lean(pose): oop_types.append({ 'type': 'side_lean', 'severity': 'medium', 'description': '乘员侧向倾斜,可能靠近侧气帘', 'action': '调整侧气帘展开策略' }) if self._detect_excessive_recline(pose): oop_types.append({ 'type': 'excessive_recline', 'severity': 'medium', 'description': '座椅过度后仰', 'action': '调整安全带预紧力' }) if self._detect_child_misposition(pose, seat_position): oop_types.append({ 'type': 'child_misposition', 'severity': 'critical', 'description': '儿童未在儿童座椅,或位置异常', 'action': '禁用所有安全气囊' }) return { 'seat': seat_position, 'oop_detected': len(oop_types) > 0, 'oop_types': oop_types, 'recommendation': self._generate_recommendation(oop_types) } def _detect_forward_lean(self, pose: np.ndarray) -> bool: """检测前倾""" head = pose[0] chest = pose[10] head_forward = head[2] - chest[2] return head_forward > self.thresholds['forward_lean'] def _detect_side_lean(self, pose: np.ndarray) -> bool: """检测侧倾""" left_shoulder = pose[4] right_shoulder = pose[5] height_diff = np.abs(left_shoulder[1] - right_shoulder[1]) return height_diff > self.thresholds['side_lean'] def _detect_excessive_recline(self, pose: np.ndarray) -> bool: """检测过度后仰""" chest = pose[10] pelvis = pose[11] head = pose[0] torso_vector = chest - pelvis angle = np.arctan2(torso_vector[1], torso_vector[2]) * 180 / np.pi return np.abs(angle) > self.thresholds['recline_angle'] def _detect_child_misposition(self, pose: np.ndarray, seat_position: str) -> bool: """检测儿童位置异常""" left_shoulder = pose[4] right_shoulder = pose[5] shoulder_width = np.linalg.norm(left_shoulder - right_shoulder) is_child = shoulder_width < 0.3 if is_child and seat_position in ['driver', 'passenger']: return True return False def _generate_recommendation(self, oop_types: List[Dict]) -> str: """生成安全建议""" if not oop_types: return "姿态正常" severity_order = {'critical': 0, 'high': 1, 'medium': 2, 'low': 3} oop_types_sorted = sorted(oop_types, key=lambda x: severity_order[x['severity']]) return oop_types_sorted[0]['action']
if __name__ == "__main__": vehicle_config = { 'front_airbag_pos': {'driver': [0.5, 0.3, 0.8]}, 'side_airbag_pos': {'driver': [0.3, 0.1, 0.5]} } oop_detector = OOPDetector(vehicle_config) pose_forward_lean = np.array([ [0, 0, 0.5], [-0.05, 0, 0.1], [0.05, 0, 0.1], [0, 0, 0.1], [-0.15, 0.1, 0], [0.15, 0.1, 0], [-0.2, 0, 0.1], [0.2, 0, 0.1], [-0.25, -0.1, 0.2], [0.25, -0.1, 0.2], [0, 0, 0], [0, -0.1, -0.2], [-0.1, -0.2, -0.3], [0.1, -0.2, -0.3], [-0.1, -0.4, -0.4], [0.1, -0.4, -0.4] ]) result = oop_detector.detect_oop(pose_forward_lean, 'driver') print(f"OOP检测结果: {result}")
|