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
| DRIVING_TASK_REGIONS = { "front_windshield": { "description": "前挡风玻璃区域", "gaze_yaw_range": (-30, 30), "gaze_pitch_range": (-20, 10) }, "left_mirror": { "description": "左侧后视镜", "gaze_yaw_range": (-60, -30), "gaze_pitch_range": (-10, 10) }, "right_mirror": { "description": "右侧后视镜", "gaze_yaw_range": (30, 60), "gaze_pitch_range": (-10, 10) }, "instrument_cluster": { "description": "仪表盘", "gaze_yaw_range": (-15, 15), "gaze_pitch_range": (-40, -20) } }
DISTRACTION_REGIONS = { "center_console": { "description": "中控屏幕/手机", "gaze_pitch_range": (-60, -40), "gaze_yaw_range": (-20, 20) }, "passenger_seat": { "description": "副驾方向", "gaze_yaw_range": (45, 90) }, "rear_seats": { "description": "后排方向", "gaze_yaw_range": (-90, -45) }, "lap": { "description": "腿部/手机", "gaze_pitch_range": (-80, -60) } }
def check_addw_violation(gaze_yaw, gaze_pitch, speed_kmh, time_in_distraction_s): """ 检查是否违反ADDW法规 Args: gaze_yaw: 视线偏航角 (degrees) gaze_pitch: 视线俯仰角 (degrees) speed_kmh: 车速 (km/h) time_in_distraction_s: 视线在分心区域的持续时间 (秒) Returns: violation: bool 是否违规 threshold: float 适用的阈值 """ if speed_kmh >= 50: threshold = 3.5 elif speed_kmh >= 20: threshold = 6.0 else: return False, None in_driving_task = False for region, ranges in DRIVING_TASK_REGIONS.items(): yaw_ok = ranges["gaze_yaw_range"][0] <= gaze_yaw <= ranges["gaze_yaw_range"][1] pitch_ok = ranges["gaze_pitch_range"][0] <= gaze_pitch <= ranges["gaze_pitch_range"][1] if yaw_ok and pitch_ok: in_driving_task = True break if not in_driving_task and time_in_distraction_s > threshold: return True, threshold return False, threshold
if __name__ == "__main__": test_cases = [ (0, 0, 80, 2.0, False, "正常看前方"), (50, 0, 80, 4.0, True, "看副驾>3.5s@80km/h"), (50, 0, 30, 7.0, True, "看副驾>6s@30km/h"), (50, 0, 30, 5.0, False, "看副驾5s@30km/h(未超6s)"), (-45, -50, 60, 4.0, True, "看中控>3.5s@60km/h"), (0, 0, 10, 10.0, False, "低速不激活ADDW"), ] print(f"{'场景':<30} {'违规?':<8} {'阈值':<8}") print("-" * 50) for yaw, pitch, speed, time, expected, desc in test_cases: violation, threshold = check_addw_violation(yaw, pitch, speed, time) status = "✅" if violation == expected else "❌" print(f"{desc:<30} {status}{'是' if violation else '否':<7} {threshold}")
|