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
| """ 摄像头辅助儿童座椅识别 参考:Euro NCAP 2026 OMS要求
儿童座椅特征: - ISOFIX固定点(金属锚点) - 后向/前向姿态 - 安全带路由(5点式) - 儿童座椅形状特征 """
import numpy as np import cv2 from typing import Dict, List, Tuple
class ChildSeatDetector: """ 儿童座椅检测器 检测特征: 1. ISOFIX锚点(金属圆形特征) 2. 儿童座椅轮廓(标准形状) 3. 安全带路由(5点式特征) 4. 后向/前向姿态 """ def __init__(self): self.isofix_positions = { 'left': (0.2, 0.8), 'right': (0.8, 0.8) } self.child_seat_features = { 'width_ratio': 0.6, 'height_ratio': 0.4, 'five_point_belt': True } def detect_isofix( self, seat_image: np.ndarray ) -> bool: """ 检测ISOFIX锚点 Args: seat_image: 座椅区域图像 Returns: detected: 是否检测到ISOFIX 方法: - 在座椅底部左右角搜索金属圆形特征 - ISOFIX锚点:直径约30mm金属圆环 """ H, W = seat_image.shape[:2] left_roi = seat_image[int(H*0.85):, :int(W*0.3)] right_roi = seat_image[int(H*0.85):, int(W*0.7):] left_gray = cv2.cvtColor(left_roi, cv2.COLOR_BGR2GRAY) right_gray = cv2.cvtColor(right_roi, cv2.COLOR_BGR2GRAY) left_bright = np.sum(left_gray > 200) / left_gray.size right_bright = np.sum(right_gray > 200) / right_gray.size detected = left_bright > 0.05 and right_bright > 0.05 return detected def detect_orientation( self, seat_image: np.ndarray ) -> str: """ 检测儿童座椅朝向 Args: seat_image: 座椅区域图像 Returns: orientation: 'forward' / 'rearward' / 'none' 后向特征: - 儿童座椅背面朝前 - 儿童面向后方 前向特征: - 儿童座椅正面朝前 - 儿童面向前方 """ gray = cv2.cvtColor(seat_image, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 50, 150) contours = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) orientation = 'forward' return orientation def classify_child_seat( self, seat_image: np.ndarray, capacitance_data: Dict ) -> Dict: """ 综合分类儿童座椅状态 Args: seat_image: 座椅图像 capacitance_data: 电容传感器数据 Returns: result: 分类结果 - type: 'child_seat_forward' / 'child_seat_rearward' / 'none' - has_child: True/False - confidence: 0-1 """ isofix = self.detect_isofix(seat_image) orientation = self.detect_orientation(seat_image) has_child = capacitance_data['center_cap'] > 10 if isofix: seat_type = f'child_seat_{orientation}' else: seat_type = 'none' confidence = 0.85 if isofix else 0.3 return { 'type': seat_type, 'has_child': has_child, 'isofix_detected': isofix, 'orientation': orientation, 'confidence': confidence }
if __name__ == "__main__": detector = ChildSeatDetector() seat_image = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8) cap_data = {'center_cap': 15} result = detector.classify_child_seat(seat_image, cap_data) print(f"儿童座椅检测结果:") print(f" 类型: {result['type']}") print(f" 有儿童: {result['has_child']}") print(f" ISOFIX检测: {result['isofix_detected']}") print(f" 朝向: {result['orientation']}") print(f" 置信度: {result['confidence']:.2f}")
|