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
| """ 基于DMS摄像头的酒驾行为检测
参考论文:CycleGAN-Based Drunk Synthesis (97.67%准确率) """
import numpy as np
class AlcoholImpairmentDetector: """ 酒精损伤视觉检测器 特征: 1. 面部潮红 (Skin Flushing) 2. 眼睛充血 (Periocular Redness) 3. 视线不规则 (Gaze Irregularities) 4. 反应迟缓 (Delayed Response) """ def __init__(self): self.flush_threshold = 0.3 self.gaze_variance_threshold = 0.5 self.blink_rate_normal = (15, 25) def detect_skin_flush(self, face_roi: np.ndarray) -> float: """ 检测面部潮红 Args: face_roi: 面部区域RGB图像 Returns: 潮红程度 (0-1) """ r_channel = face_roi[:, :, 0].astype(float) g_channel = face_roi[:, :, 1].astype(float) rg_ratio = np.mean(r_channel / (g_channel + 1)) flush_score = np.clip((rg_ratio - 1.0) / 0.5, 0, 1) return flush_score def detect_gaze_irregularity(self, gaze_history: list) -> float: """ 检测视线不规则性 Args: gaze_history: 历史视线点序列 [(x, y), ...] Returns: 不规则程度 (0-1) """ if len(gaze_history) < 30: return 0.0 gaze_array = np.array(gaze_history) variance = np.var(gaze_array, axis=0) total_variance = np.sum(variance) irregularity = np.clip(total_variance / 100, 0, 1) return irregularity def detect_blink_anomaly(self, blink_count: int, duration_sec: float) -> bool: """ 检测眨眼异常 酒后眨眼频率通常降低 """ blink_rate = blink_count / (duration_sec / 60) return blink_rate < self.blink_rate_normal[0] def detect_impairment( self, face_roi: np.ndarray, gaze_history: list, blink_count: int, duration_sec: float ) -> dict: """ 综合判断酒精损伤 Returns: { 'flush_score': 潮红程度, 'gaze_irregularity': 视线不规则, 'blink_anomaly': 眨眼异常, 'is_impaired': 是否损伤 } """ flush = self.detect_skin_flush(face_roi) gaze_irr = self.detect_gaze_irregularity(gaze_history) blink_anom = self.detect_blink_anomaly(blink_count, duration_sec) impairment_score = ( flush * 0.4 + gaze_irr * 0.4 + (1.0 if blink_anom else 0.0) * 0.2 ) return { 'flush_score': flush, 'gaze_irregularity': gaze_irr, 'blink_anomaly': blink_anom, 'is_impaired': impairment_score > 0.5 }
|