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
| import numpy as np
class OOPDetector: def __init__(self): self.dashboard_distance_threshold = 0.20 self.warning_cooldown = 900 def detect_feet_on_dashboard(self, keypoints_3d): """ 检测脚踩仪表板 参数: keypoints_3d: 3D 关键点坐标 {'left_foot': (x,y,z), 'right_foot': (x,y,z), ...} 返回: {'detected': bool, 'position': str} """ dashboard_height = 0.5 left_foot = keypoints_3d.get('left_foot', (0, 0, 0)) right_foot = keypoints_3d.get('right_foot', (0, 0, 0)) if left_foot[1] > dashboard_height or right_foot[1] > dashboard_height: foot_x = max(left_foot[0], right_foot[0]) vehicle_center = 0 if foot_x < vehicle_center - 0.3: position = 'inboard' elif foot_x > vehicle_center + 0.3: position = 'outboard' else: position = 'centerline' return {'detected': True, 'position': position} return {'detected': False, 'position': None} def detect_body_too_close(self, keypoints_3d, dashboard_position): """ 检测身体过于靠前 参数: keypoints_3d: 3D 关键点坐标 dashboard_position: 仪表板位置 (x, y, z) 返回: {'detected': bool, 'distance': float} """ head = keypoints_3d.get('head', (0, 0, 0)) distance = np.sqrt( (head[0] - dashboard_position[0])**2 + (head[1] - dashboard_position[1])**2 + (head[2] - dashboard_position[2])**2 ) return { 'detected': distance < self.dashboard_distance_threshold, 'distance': distance }
|