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
|
import numpy as np from typing import Tuple
class SeatbeltMisuseDetector: """ 安全带误用检测器 融合视觉和传感器数据: 1. 摄像头检测安全带位置 2. 带扣传感器检测佩戴状态 3. 座椅压力传感器检测乘员存在 参照 Euro NCAP 2026 SBR 要求 """ def __init__(self): self.buckle_engaged = False self.seat_occupied = False self.visual_confidence = 0.0 self.misuse_type = "none" def check_misuse(self, visual_belt_position: dict, buckle_state: bool, seat_pressure: float) -> Tuple[bool, str]: """ 检测安全带误用 Args: visual_belt_position: 视觉检测结果 {'shoulder': {'detected': bool, 'position': str}, 'lap': {'detected': bool, 'position': str}, 'confidence': float} buckle_state: 带扣是否扣合 seat_pressure: 座椅压力 (kg) Returns: (is_misuse, misuse_type) """ self.buckle_engaged = buckle_state self.seat_occupied = seat_pressure > 20.0 self.visual_confidence = visual_belt_position.get('confidence', 0.0) if self.seat_occupied and not self.buckle_engaged: return True, "unfastened" if visual_belt_position.get('lap', {}).get('position') == 'behind_back': return True, "lap_behind_back" if visual_belt_position.get('shoulder', {}).get('position') == 'under_arm': return True, "shoulder_under_arm" if (self.buckle_engaged and self.seat_occupied and not visual_belt_position.get('shoulder', {}).get('detected', False) and self.visual_confidence > 0.7): return True, "belt_slack" return False, "none"
if __name__ == "__main__": detector = SeatbeltMisuseDetector() visual_normal = { 'shoulder': {'detected': True, 'position': 'normal'}, 'lap': {'detected': True, 'position': 'normal'}, 'confidence': 0.95 } misuse, mtype = detector.check_misuse(visual_normal, True, 65.0) print(f"正常佩戴: misuse={misuse}, type={mtype}") visual_behind = { 'shoulder': {'detected': True, 'position': 'normal'}, 'lap': {'detected': True, 'position': 'behind_back'}, 'confidence': 0.88 } misuse, mtype = detector.check_misuse(visual_behind, True, 65.0) print(f"腰带背后: misuse={misuse}, type={mtype}") visual_none = { 'shoulder': {'detected': False, 'position': 'none'}, 'lap': {'detected': False, 'position': 'none'}, 'confidence': 0.92 } misuse, mtype = detector.check_misuse(visual_none, False, 65.0) print(f"未系安全带: misuse={misuse}, type={mtype}")
|