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
| """ 多传感器融合 DMS 架构
融合层级: 1. 数据层融合(原始数据) 2. 特征层融合(中间特征) 3. 决策层融合(最终输出) """
import numpy as np from typing import Dict, List
class MultiSensorFusionDMS: """多传感器融合 DMS""" def __init__(self): self.camera_processor = CameraProcessor() self.radar_processor = RadarProcessor() self.steering_processor = SteeringProcessor() self.seat_processor = SeatProcessor() self.feature_fusion = FeatureFusion() self.decision_fusion = DecisionFusion() def process(self, sensor_data: Dict) -> Dict: """ 处理多传感器数据 Args: sensor_data: { "camera": frame, "radar": radar_frame, "steering": torque_data, "seat": pressure_map } Returns: 融合后的检测结果 """ camera_features = self.camera_processor.extract_features( sensor_data.get("camera") ) radar_features = self.radar_processor.extract_features( sensor_data.get("radar") ) steering_features = self.steering_processor.extract_features( sensor_data.get("steering") ) seat_features = self.seat_processor.extract_features( sensor_data.get("seat") ) fused_features = self.feature_fusion.fuse({ "camera": camera_features, "radar": radar_features, "steering": steering_features, "seat": seat_features }) camera_decision = self.camera_processor.decide(camera_features) radar_decision = self.radar_processor.decide(radar_features) steering_decision = self.steering_processor.decide(steering_features) final_decision = self.decision_fusion.fuse({ "camera": camera_decision, "radar": radar_decision, "steering": steering_decision }) return { "fatigue_level": final_decision.get("fatigue", "none"), "distraction_level": final_decision.get("distraction", "none"), "occupancy": fused_features.get("occupancy", True), "vital_signs": fused_features.get("vital_signs"), "confidence": final_decision.get("confidence", 0.0) }
class CameraProcessor: """摄像头处理器""" def extract_features(self, frame) -> dict: if frame is None: return {} return { "face_landmarks": [], "gaze_vector": [], "eye_closure": 0.3, "head_pose": [] } def decide(self, features) -> dict: return { "fatigue": "moderate" if features.get("eye_closure", 0) > 0.5 else "none", "confidence": 0.85 }
class RadarProcessor: """雷达处理器""" def extract_features(self, frame) -> dict: if frame is None: return {} return { "occupancy": True, "breathing_rate": 16, "micro_movement": True } def decide(self, features) -> dict: return { "fatigue": "none", "confidence": 0.7 }
class SteeringProcessor: """方向盘处理器""" def extract_features(self, data) -> dict: if data is None: return {} return { "torque_variance": 0.5, "hands_on_wheel": True, "correction_frequency": 2.0 } def decide(self, features) -> dict: if features.get("torque_variance", 0) > 1.0: return {"fatigue": "moderate", "confidence": 0.6} return {"fatigue": "none", "confidence": 0.6}
class SeatProcessor: """座椅处理器""" def extract_features(self, data) -> dict: if data is None: return {} return { "posture": "normal", "pressure_distribution": [] }
class FeatureFusion: """特征融合""" def fuse(self, features_dict: Dict) -> dict: """融合多传感器特征""" fused = {} for sensor, features in features_dict.items(): if features: fused.update(features) return fused
class DecisionFusion: """决策融合""" def __init__(self): self.weights = { "camera": 0.5, "radar": 0.2, "steering": 0.3 } def fuse(self, decisions: Dict) -> dict: """融合决策""" fatigue_votes = {"none": 0, "mild": 0, "moderate": 0, "severe": 0} for sensor, decision in decisions.items(): level = decision.get("fatigue", "none") weight = self.weights.get(sensor, 0.3) confidence = decision.get("confidence", 0.5) fatigue_votes[level] += weight * confidence final_fatigue = max(fatigue_votes, key=fatigue_votes.get) final_confidence = fatigue_votes[final_fatigue] return { "fatigue": final_fatigue, "confidence": final_confidence }
if __name__ == "__main__": dms = MultiSensorFusionDMS() sensor_data = { "camera": np.random.randint(0, 255, (1080, 1920, 3), dtype=np.uint8), "radar": np.random.randn(64, 256), "steering": {"torque": 1.5}, "seat": {"pressure": np.random.randn(16, 16)} } result = dms.process(sensor_data) print(f"疲劳等级: {result['fatigue_level']}") print(f"置信度: {result['confidence']:.2%}")
|