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
| """ Minieye DFR 分级干预模型
DFR将DMS从"被动提醒"升级为"主动安全网关" 根据驾驶员功能准备度分数+ADAS场景,触发分级干预 """
from dataclasses import dataclass from enum import Enum
class InterventionLevel(Enum): """干预等级""" NONE = 0 ALERT = 1 ASSIST = 2 TAKEOVER = 3
@dataclass class DFRInput: """DFR输入数据""" perclos: float gaze_offroad: float alcohol_impairment: float head_pose_stable: bool driver_identity: str emotion_state: str vehicle_speed: float following_distance: float ttc: float lane_deviation: float pedestrian_ahead: bool
class DFRModel: """驾驶员功能准备度模型""" def __init__(self): self.weights = { "fatigue": 0.25, "distraction": 0.20, "alcohol": 0.30, "head_stability": 0.10, "emotion": 0.15 } def assess(self, inp: DFRInput) -> dict: """评估功能准备度""" fatigue_score = (1 - inp.perclos) * 100 distraction_score = (1 - inp.gaze_offroad) * 100 alcohol_score = (1 - inp.alcohol_impairment) * 100 head_score = 100 if inp.head_pose_stable else 50 emotion_score = self._emotion_score(inp.emotion_state) dfr_score = ( fatigue_score * self.weights["fatigue"] + distraction_score * self.weights["distraction"] + alcohol_score * self.weights["alcohol"] + head_score * self.weights["head_stability"] + emotion_score * self.weights["emotion"] ) if inp.ttc < 3.0: dfr_score *= 0.7 elif inp.ttc < 5.0: dfr_score *= 0.85 level = self._decide_level(dfr_score, inp) return { "dfr_score": round(dfr_score, 1), "fatigue_score": round(fatigue_score, 1), "distraction_score": round(distraction_score, 1), "alcohol_score": round(alcohol_score, 1), "intervention_level": level, "action": self._get_action(level, inp) } def _emotion_score(self, emotion: str) -> float: scores = { "neutral": 90, "happy": 95, "calm": 92, "angry": 40, "sad": 60, "stressed": 35, "drowsy": 20, "unknown": 70 } return scores.get(emotion, 70) def _decide_level(self, score: float, inp: DFRInput) -> InterventionLevel: """决策干预等级""" if score < 30 or inp.alcohol_impairment > 0.7: return InterventionLevel.TAKEOVER elif score < 50 or (inp.ttc < 3.0 and score < 70): return InterventionLevel.ASSIST elif score < 70: return InterventionLevel.ALERT else: return InterventionLevel.NONE def _get_action(self, level: InterventionLevel, inp: DFRInput) -> str: actions = { InterventionLevel.NONE: "正常驾驶", InterventionLevel.ALERT: f"座舱警告: 疲劳/分心提醒", InterventionLevel.ASSIST: f"ADAS增强: 增大跟车距离至{max(inp.following_distance*1.5, 50):.0f}m", InterventionLevel.TAKEOVER: "ADAS接管: 减速靠边停车" } return actions[level]
if __name__ == "__main__": model = DFRModel() normal = DFRInput( perclos=0.05, gaze_offroad=0.1, alcohol_impairment=0.0, head_pose_stable=True, driver_identity="Alice", emotion_state="neutral", vehicle_speed=80, following_distance=40, ttc=10.0, lane_deviation=0.1, pedestrian_ahead=False ) fatigued = DFRInput( perclos=0.35, gaze_offroad=0.2, alcohol_impairment=0.0, head_pose_stable=True, driver_identity="Alice", emotion_state="drowsy", vehicle_speed=80, following_distance=20, ttc=2.5, lane_deviation=0.3, pedestrian_ahead=True ) alcohol = DFRInput( perclos=0.1, gaze_offroad=0.15, alcohol_impairment=0.8, head_pose_stable=False, driver_identity="Bob", emotion_state="neutral", vehicle_speed=60, following_distance=30, ttc=8.0, lane_deviation=0.2, pedestrian_ahead=False ) for name, inp in [("正常", normal), ("疲劳+紧急", fatigued), ("酒驾", alcohol)]: result = model.assess(inp) print(f"\n=== {name} ===") print(f"DFR分数: {result['dfr_score']}") print(f"疲劳: {result['fatigue_score']} | 分心: {result['distraction_score']} | 酒驾: {result['alcohol_score']}") print(f"干预等级: {result['intervention_level'].name}") print(f"动作: {result['action']}")
|