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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
| import numpy as np from typing import Dict, Tuple, Optional
class CPDFusionDetector: """ CPD多传感器融合检测器 融合策略: 1. 雷达优先:检测呼吸/心跳微动 2. 视觉验证:分类目标是儿童还是物品 3. 热成像辅助:区分活体与非活体 4. 重量传感器:座椅占用状态 """ def __init__(self, config): self.radar_detector = RadarCPDDetector( frequency='60GHz', bandwidth='4GHz', detection_threshold=0.7 ) self.vision_detector = VisionCPDDetector( model='yolov8-child', confidence_threshold=0.6 ) self.thermal_detector = ThermalDetector( temp_threshold=35.0 ) self.weights = { 'radar': 0.5, 'vision': 0.3, 'thermal': 0.15, 'weight': 0.05 } def detect(self, sensor_data: Dict) -> Dict: """ 多传感器融合检测 Args: sensor_data: { 'radar': 雷达数据, 'image': 图像, 'thermal': 热成像, 'weight': 座椅重量 } Returns: { 'child_detected': bool, 'confidence': float, 'location': Tuple[int, int], 'vital_signs': Dict, 'alert_level': int } """ radar_result = self.radar_detector.detect(sensor_data['radar']) vision_result = self.vision_detector.detect(sensor_data['image']) thermal_result = self.thermal_detector.detect(sensor_data['thermal']) weight_result = self._check_weight(sensor_data['weight']) features = self._extract_features( radar_result, vision_result, thermal_result, weight_result ) decision = self._fuse_decisions( radar_result, vision_result, thermal_result, weight_result ) child_detected = decision['confidence'] > 0.75 return { 'child_detected': child_detected, 'confidence': decision['confidence'], 'location': decision.get('location'), 'vital_signs': radar_result.get('vital_signs'), 'alert_level': self._calculate_alert_level(decision) } def _extract_features(self, radar, vision, thermal, weight): """提取多模态特征""" return { 'breathing_detected': radar.get('breathing_detected', False), 'breathing_rate': radar.get('breathing_rate', 0), 'heart_rate': radar.get('heart_rate', 0), 'child_classified': vision.get('child_detected', False), 'bounding_box': vision.get('bounding_box'), 'temperature': thermal.get('temperature', 0), 'seat_occupied': weight.get('occupied', False) } def _fuse_decisions(self, radar, vision, thermal, weight): """ 决策级融合 规则: 1. 雷达检测到呼吸 → 高置信度 2. 视觉分类为儿童 → 增强置信度 3. 热成像确认活体 → 进一步确认 4. 座椅占用 → 基础条件 """ confidence = 0.0 if radar.get('breathing_detected'): confidence += self.weights['radar'] if radar.get('heart_rate_detected'): confidence += 0.1 if vision.get('child_detected'): confidence += self.weights['vision'] if thermal.get('living_body'): confidence += self.weights['thermal'] if weight.get('occupied'): confidence += self.weights['weight'] if radar.get('breathing_detected') and vision.get('child_detected'): confidence += 0.1 return { 'confidence': min(confidence, 1.0), 'location': vision.get('location') or radar.get('location') } def _calculate_alert_level(self, decision): """ 警报等级计算 Level 0: 无儿童 Level 1: 疑似儿童,需确认 Level 2: 儿童检测,温度正常 Level 3: 儿童检测,温度危险 """ if decision['confidence'] < 0.5: return 0 elif decision['confidence'] < 0.75: return 1 else: return 2
class RadarCPDDetector: """雷达CPD检测器""" def __init__(self, frequency, bandwidth, detection_threshold): self.frequency = frequency self.bandwidth = bandwidth self.threshold = detection_threshold def detect(self, radar_data): """ 雷达检测 关键指标: - 呼吸频率:6-30次/分(儿童略快) - 呼吸幅度:胸部起伏约3-5mm - 心跳频率:80-140次/分(儿童较快) """ vital_signs = self._extract_vital_signs(radar_data) breathing_detected = ( 6 <= vital_signs['breathing_rate'] <= 30 and vital_signs['breathing_snr'] > 10 ) heart_rate_detected = ( 80 <= vital_signs['heart_rate'] <= 140 and vital_signs['heart_rate_snr'] > 5 ) return { 'breathing_detected': breathing_detected, 'heart_rate_detected': heart_rate_detected, 'vital_signs': vital_signs, 'location': vital_signs.get('range_bin') } def _extract_vital_signs(self, radar_data): """提取生命体征""" return { 'breathing_rate': 20, 'heart_rate': 100, 'breathing_snr': 15, 'heart_rate_snr': 8 }
if __name__ == "__main__": config = { 'radar': {'frequency': '60GHz', 'bandwidth': '4GHz'}, 'vision': {'model': 'yolov8-child'}, 'thermal': {'temp_threshold': 35.0} } detector = CPDFusionDetector(config) sensor_data = { 'radar': np.random.randn(128, 256), 'image': np.random.rand(480, 640, 3), 'thermal': np.random.rand(60, 80), 'weight': 15.0 } result = detector.detect(sensor_data) print(f"儿童检测: {result['child_detected']}") print(f"置信度: {result['confidence']:.2%}") print(f"呼吸率: {result['vital_signs']['breathing_rate']:.1f} 次/分") print(f"心率: {result['vital_signs']['heart_rate']:.1f} 次/分") print(f"警报等级: {result['alert_level']}")
|