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
| class CPDSystem: """ 儿童存在检测系统 检测流程: 1. 雷达信号采集 2. 目标检测(距离-角度) 3. 生命体征提取 4. 儿童判定(体型+心率+呼吸率) 5. 警告触发 """ def __init__(self): self.radar = FMCWRadar(config={}) self.vitals_extractor = VitalSignsExtractor() self.child_classifier = ChildClassifier() def detect(self, radar_frame): """ CPD检测 Returns: result: dict - child_detected: bool - location: dict - vital_signs: dict - confidence: float """ targets = self.detect_targets(radar_frame) for target in targets: vital_signs = self.vitals_extractor.extract( radar_frame, target ) is_child, confidence = self.child_classifier.classify( target, vital_signs ) if is_child: return { 'child_detected': True, 'location': target['location'], 'vital_signs': vital_signs, 'confidence': confidence } return { 'child_detected': False, 'location': None, 'vital_signs': None, 'confidence': 0.0 } def detect_targets(self, radar_frame): """ 目标检测(CFAR算法) """ range_fft = np.fft.fft(radar_frame, axis=1) doppler_fft = np.fft.fft(range_fft, axis=0) targets = self.cfar_detect(np.abs(doppler_fft)) return targets def cfar_detect(self, detection_map, threshold_factor=10): """ CFAR(恒虚警率)检测 自适应阈值检测目标 """ targets = [] for i in range(10, detection_map.shape[0] - 10): for j in range(10, detection_map.shape[1] - 10): training_cells = detection_map[ i-10:i+10, j-10:j+10 ].flatten() training_cells = np.delete(training_cells, 100) noise_level = np.mean(training_cells) threshold = noise_level * threshold_factor if detection_map[i, j] > threshold: range_bin = j doppler_bin = i target = { 'range': range_bin * 0.0375, 'velocity': (doppler_bin - len(detection_map)/2) * 0.1, 'location': self.bin_to_location(range_bin, doppler_bin) } targets.append(target) return targets def bin_to_location(self, range_bin, doppler_bin): """ 转换为座椅位置 """ if range_bin < 40: seat = 'front_passenger' elif range_bin < 80: seat = 'rear_left' else: seat = 'rear_right' return {'seat': seat}
class ChildClassifier: """ 儿童分类器 儿童特征: - 体型小(雷达反射面积<0.5 m²) - 心率高(80-120 bpm vs 成人60-80) - 呼吸率高(20-30 bpm vs 成人12-20) """ def classify(self, target, vital_signs): """ 儿童判定 """ score = 0 if target.get('size', 1.0) < 0.5: score += 0.3 if vital_signs['heart_rate'] > 80: score += 0.3 if vital_signs['heart_rate'] > 100: score += 0.1 if vital_signs['respiration_rate'] > 20: score += 0.2 if vital_signs['respiration_rate'] > 25: score += 0.1 confidence = min(score, 1.0) is_child = confidence > 0.6 return is_child, confidence
def test_euro_ncap_cpd(): """ Euro NCAP CPD测试 场景: - CPD-01: 婴儿熟睡(覆盖毯子) - CPD-02: 儿童移动 - CPD-03: 婴儿哭闹 - CPD-04: 后排角落 """ cpd_system = CPDSystem() radar_frame_sim = simulate_occluded_child() start_time = time.time() result = cpd_system.detect(radar_frame_sim) detection_latency = time.time() - start_time print("\n" + "="*60) print("Euro NCAP CPD-01测试(穿透毯子)") print("="*60) print(f"\n儿童检测: {result['child_detected']}") print(f"检测时延: {detection_latency:.1f}秒") if result['child_detected']: print(f"\n位置: {result['location']['seat']}") print(f"心率: {result['vital_signs']['heart_rate']:.1f} bpm") print(f"呼吸率: {result['vital_signs']['respiration_rate']:.1f} bpm") print(f"置信度: {result['confidence']:.2f}") if detection_latency <= 30 and result['confidence'] > 0.7: print("\n✓ Euro NCAP CPD-01通过") else: print(f"\n✗ Euro NCAP CPD-01未通过") print("="*60)
if __name__ == "__main__": test_euro_ncap_cpd()
|