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
| class AlcoholImpairmentDetector: """ Smart Eye酒精损伤检测模型 检测指标: 1. 眼动模式:扫视速度下降、凝视时间增加 2. 面部特征:面部肌肉松弛、表情呆滞 3. 头部运动:反应延迟、微动作减少 """ def __init__(self): self.gaze_analyzer = GazePatternAnalyzer() self.expression_analyzer = FacialExpressionAnalyzer() self.head_motion_analyzer = HeadMotionAnalyzer() self.fusion_classifier = MultiModalFusion() def detect(self, frames, gaze_data, head_pose_data): """ 检测酒精损伤状态 Args: frames: (T, 3, H, W) 视频序列 gaze_data: (T, 3) 视线方向序列 head_pose_data: (T, 3) 头部姿态序列 Returns: impairment_prob: 酒精损伤概率 confidence: 置信度 """ gaze_features = self.gaze_analyzer.extract_patterns(gaze_data) expression_features = self.expression_analyzer.analyze(frames) motion_features = self.head_motion_analyzer.analyze(head_pose_data) features = { 'gaze': gaze_features, 'expression': expression_features, 'motion': motion_features } impairment_prob = self.fusion_classifier.predict(features) return impairment_prob
class GazePatternAnalyzer: """ 眼动模式分析器 酒精损伤特征: - 扫视速度下降30-50% - 凝视时间增加 - 视线切换频率降低 """ def extract_patterns(self, gaze_sequence): """ 提取眼动模式特征 Args: gaze_sequence: (T, 3) 视线方向序列 Returns: features: dict """ saccade_velocity = self._compute_saccade_velocity(gaze_sequence) fixation_duration = self._compute_fixation_duration(gaze_sequence) gaze_switch_rate = self._compute_gaze_switch_rate(gaze_sequence) return { 'saccade_velocity': saccade_velocity, 'fixation_duration': fixation_duration, 'gaze_switch_rate': gaze_switch_rate } def _compute_saccade_velocity(self, gaze_seq): """计算扫视速度(度/秒)""" delta = torch.diff(gaze_seq, dim=0) angular_change = torch.norm(delta, dim=-1) velocity = torch.mean(angular_change).item() return velocity def _compute_fixation_duration(self, gaze_seq): """计算平均凝视时间(毫秒)""" velocity = torch.norm(torch.diff(gaze_seq, dim=0), dim=-1) fixation_mask = velocity < 0.01 fixation_durations = [] current_duration = 0 for is_fixation in fixation_mask: if is_fixation: current_duration += 33 else: if current_duration > 0: fixation_durations.append(current_duration) current_duration = 0 return np.mean(fixation_durations) if fixation_durations else 0
|