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
| """ ATC 警觉力监测多模态融合框架 迁移到汽车 DMS """ import numpy as np
class MultimodalVigilanceFusion: """多模态警觉力融合检测""" def __init__(self): self.weights = { "eeg_theta_alpha_ratio": 0.30, "eye_blink_rate": 0.25, "hrv_lf_hf_ratio": 0.20, "pupil_diameter": 0.15, "steering_entropy": 0.10, } def compute_vigilance_score(self, features: dict) -> float: """ 计算综合警觉力评分 Args: features: 各传感器提取的特征 Returns: vigilance_score: 0(完全衰退) - 1(最佳状态) """ score = 1.0 if "eeg_theta_alpha_ratio" in features: ratio = features["eeg_theta_alpha_ratio"] eeg_impact = max(0, (ratio - 2.0) / 2.0) * self.weights["eeg_theta_alpha_ratio"] score -= eeg_impact if "eye_blink_rate" in features: rate = features["eye_blink_rate"] blink_impact = max(0, (rate - 20) / 15) * self.weights["eye_blink_rate"] score -= blink_impact if "hrv_lf_hf_ratio" in features: ratio = features["hrv_lf_hf_ratio"] hrv_impact = max(0, (2.0 - ratio) / 2.0) * self.weights["hrv_lf_hf_ratio"] score -= hrv_impact if "pupil_diameter_cv" in features: cv = features["pupil_diameter_cv"] pupil_impact = min(0.15, cv * 0.5) * self.weights["pupil_diameter"] score -= pupil_impact if "steering_entropy" in features: entropy = features["steering_entropy"] steer_impact = max(0, (entropy - 0.5) / 0.5) * self.weights["steering_entropy"] score -= steer_impact return max(0, min(1, score)) def get_alert_level(self, score: float) -> dict: """根据评分获取告警级别""" if score > 0.7: return {"level": "normal", "action": "none", "color": "green"} elif score > 0.5: return {"level": "caution", "action": "audio_alert", "color": "yellow"} elif score > 0.3: return {"level": "warning", "action": "hud_alert+seat_vibration", "color": "orange"} else: return {"level": "critical", "action": "pull_over_safely", "color": "red"}
fusion = MultimodalVigilanceFusion()
normal_features = { "eye_blink_rate": 15, "hrv_lf_hf_ratio": 3.0, "pupil_diameter_cv": 0.05, "steering_entropy": 0.3, } score1 = fusion.compute_vigilance_score(normal_features) print(f"正常驾驶 - 警觉力评分: {score1:.2f}") print(f" → {fusion.get_alert_level(score1)}")
fatigued_features = { "eye_blink_rate": 28, "hrv_lf_hf_ratio": 1.2, "pupil_diameter_cv": 0.12, "steering_entropy": 0.7, } score2 = fusion.compute_vigilance_score(fatigued_features) print(f"疲劳驾驶 - 警觉力评分: {score2:.2f}") print(f" → {fusion.get_alert_level(score2)}")
|