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
| import numpy as np from typing import Tuple
class SuddenSicknessDetector: """ 突发疾病检测器 基于 PMC 综述框架: 1. 感知: 多模态生理信号 2. 分析: 疾病模式识别 3. 决策: 紧急状态分级 4. 干预: 安全停车+紧急呼叫 """ def __init__(self): self.state = 'normal' self.alert_duration = 0 def detect( self, head_pose: Tuple, eye_openness: Tuple, body_motion: float, breathing_rate: float, heart_rate: float, skin_color: np.ndarray, seat_pressure: np.ndarray, timestamp: float ) -> dict: """突发疾病检测""" seizure_score = self._detect_seizure(body_motion, eye_openness) cardiac_score = self._detect_cardiac_arrest(heart_rate, breathing_rate) stroke_score = self._detect_stroke(skin_color, head_pose) syncope_score = self._detect_syncope(head_pose, eye_openness, seat_pressure) scores = { 'seizure': seizure_score, 'cardiac': cardiac_score, 'stroke': stroke_score, 'syncope': syncope_score } max_disease = max(scores, key=scores.get) max_score = scores[max_disease] if max_score > 0.8: self.state = 'emergency' self.alert_duration += 1 elif max_score > 0.5: self.state = 'warning' else: self.state = 'normal' self.alert_duration = 0 return { 'state': self.state, 'likely_condition': max_disease if max_score > 0.5 else 'none', 'confidence': max_score, 'all_scores': scores, 'action': self._get_action() } def _detect_seizure(self, motion, eyes): motion_score = min(motion / 10, 1.0) eye_score = 1.0 - np.mean(eyes) return 0.6 * motion_score + 0.4 * eye_score def _detect_cardiac_arrest(self, hr, br): hr_score = 1.0 if hr < 30 or hr > 200 else 0.0 br_score = 1.0 if br < 5 else 0.0 return max(hr_score, br_score * 0.8) def _detect_stroke(self, skin, pose): asymmetry = abs(pose[1]) return min(asymmetry / 30, 1.0) def _detect_syncope(self, pose, eyes, pressure): pitch_score = min(pose[0] / 45, 1.0) eye_score = 1.0 - np.mean(eyes) pressure_var = np.std(pressure) return 0.4*pitch_score + 0.3*eye_score + 0.3*min(pressure_var, 1.0) def _get_action(self): if self.state == 'emergency': return { 'level': 3, 'actions': ['自动靠边停车', '紧急呼叫', '车门解锁', 'ADAS介入'] } elif self.state == 'warning': return { 'level': 2, 'actions': ['语音提示', '建议停车', '预紧急联系'] } return {'level': 0, 'actions': []}
if __name__ == "__main__": detector = SuddenSicknessDetector() normal = detector.detect( head_pose=(0, 0, 0), eye_openness=(0.8, 0.8), body_motion=0.2, breathing_rate=16, heart_rate=72, skin_color=np.random.rand(3), seat_pressure=np.random.rand(16), timestamp=0 ) print(f"正常: {normal['state']}, {normal['likely_condition']}") seizure = detector.detect( head_pose=(20, 5, 10), eye_openness=(0.1, 0.1), body_motion=8.5, breathing_rate=25, heart_rate=150, skin_color=np.random.rand(3), seat_pressure=np.random.rand(16), timestamp=1 ) print(f"癫痫: {seizure['state']}, {seizure['likely_condition']}, {seizure['action']}")
|