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
| class ImpairmentDetector: """ 多模态损伤检测 """ def __init__(self): self.gaze_analyzer = GazeAnalyzer() self.driving_analyzer = DrivingAnalyzer() self.baseline_manager = BaselineManager() def detect_impairment(self, gaze_data, driving_data, driver_id): """ 检测驾驶员损伤状态 参数: gaze_data: 眼动数据 driving_data: 驾驶数据 driver_id: 驾驶员 ID 返回: result: { 'impairment_prob': float, # 0-1 'type': str, # 'alcohol', 'drug', 'fatigue', 'normal' 'confidence': str # 'high', 'medium', 'low' } """ baseline = self.baseline_manager.get_baseline(driver_id) gaze_features = self.gaze_analyzer.extract_features(gaze_data) gaze_deviation = self.compare_to_baseline(gaze_features, baseline['gaze']) driving_features = self.driving_analyzer.extract_features(driving_data) driving_deviation = self.compare_to_baseline(driving_features, baseline['driving']) impairment_score = self.fuse_modalities(gaze_deviation, driving_deviation) impairment_type = self.classify_impairment(gaze_features, driving_features) confidence = self.compute_confidence(impairment_score) return { 'impairment_prob': impairment_score, 'type': impairment_type, 'confidence': confidence } def compare_to_baseline(self, features, baseline): """ 与基线比较 """ deviation = {} for key, value in features.items(): if key in baseline: deviation[key] = abs(value - baseline[key]) / baseline[key] return deviation def classify_impairment(self, gaze_features, driving_features): """ 区分损伤类型 酒精损伤特征: - 扫视异常 - 眼球震颤 - 反应时间不稳定 药物损伤特征: - 眼动迟缓 - 瞳孔异常 - 头部姿态不稳定 疲劳特征: - PERCLOS 高 - 眨眼慢 - 点头频繁 """ if gaze_features.get('nystagmus_score', 0) > 0.7: return 'alcohol' elif gaze_features.get('pupil_abnormality', 0) > 0.6: return 'drug' elif gaze_features.get('perclos', 0) > 0.3: return 'fatigue' else: return 'normal'
|