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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
| """ 场景感知误报过滤系统
根据以下因素动态调整检测策略: 1. 车辆状态(速度、转向、ACC) 2. 道路环境(高速/城市/乡村) 3. 时间因素(白天/夜间) """
import numpy as np from typing import Dict, Tuple from enum import Enum
class DrivingScenario(Enum): """驾驶场景枚举""" HIGHWAY_CRUISING = "highway_cruising" CITY_DRIVING = "city_driving" PARKING = "parking" TRAFFIC_JAM = "traffic_jam" UNKNOWN = "unknown"
class ScenarioAwareFilter: """场景感知过滤器""" def __init__(self): self.scenario_config = { DrivingScenario.HIGHWAY_CRUISING: { 'distraction_threshold': 2.0, 'fatigue_threshold': 0.25, 'warning_interval': 5.0, }, DrivingScenario.CITY_DRIVING: { 'distraction_threshold': 3.0, 'fatigue_threshold': 0.30, 'warning_interval': 10.0, }, DrivingScenario.PARKING: { 'distraction_threshold': 10.0, 'fatigue_threshold': 0.40, 'warning_interval': 30.0, }, DrivingScenario.TRAFFIC_JAM: { 'distraction_threshold': 5.0, 'fatigue_threshold': 0.35, 'warning_interval': 15.0, }, } self.legal_actions = [ 'adjusting_hvac', 'adjusting_audio', 'checking_mirror', 'checking_blind_spot', 'responding_to_warning' ] def classify_scenario(self, vehicle_data: Dict) -> DrivingScenario: """ 分类驾驶场景 Args: vehicle_data: 车辆状态数据 Returns: scenario: 场景类型 """ speed = vehicle_data.get('speed', 0) steering_angle = vehicle_data.get('steering_angle', 0) acc_active = vehicle_data.get('acc_active', False) gear = vehicle_data.get('gear', 'D') if gear == 'P' or speed < 1: return DrivingScenario.PARKING if speed > 80 and acc_active and abs(steering_angle) < 5: return DrivingScenario.HIGHWAY_CRUISING if speed < 30 and vehicle_data.get('stop_and_go', False): return DrivingScenario.TRAFFIC_JAM if 30 <= speed <= 80: return DrivingScenario.CITY_DRIVING return DrivingScenario.UNKNOWN def get_threshold(self, scenario: DrivingScenario) -> Dict: """获取当前场景阈值""" return self.scenario_config.get( scenario, self.scenario_config[DrivingScenario.CITY_DRIVING] ) def is_legal_action( self, gaze_direction: Tuple[float, float], hand_position: Tuple[float, float], vehicle_data: Dict ) -> Tuple[bool, str]: """ 判断是否为合法行为 Args: gaze_direction: 视线方向(yaw, pitch) hand_position: 手部位置 vehicle_data: 车辆状态 Returns: is_legal: 是否合法 action_type: 行为类型 """ yaw, pitch = gaze_direction if -60 < yaw < -30 and -30 < pitch < 10: return True, 'adjusting_hvac' if -120 < yaw < -60: if vehicle_data.get('turn_signal_left', False): return True, 'checking_mirror' if abs(yaw) > 120: if vehicle_data.get('turn_signal_left') or vehicle_data.get('turn_signal_right'): return True, 'checking_blind_spot' return False, 'unknown' def filter_detection( self, detection_result: Dict, vehicle_data: Dict, gaze_direction: Tuple[float, float] ) -> Dict: """ 过滤检测结果 Args: detection_result: 原始检测结果 vehicle_data: 车辆状态 gaze_direction: 视线方向 Returns: filtered_result: 过滤后结果 """ scenario = self.classify_scenario(vehicle_data) threshold = self.get_threshold(scenario) is_legal, action_type = self.is_legal_action( gaze_direction, (0, 0), vehicle_data ) if is_legal: return { 'alert': False, 'reason': f'legal_action_{action_type}', 'confidence': 0.9, 'scenario': scenario.value } if detection_result['type'] == 'distraction': duration = detection_result['duration'] if duration < threshold['distraction_threshold']: return { 'alert': False, 'reason': 'duration_below_threshold', 'confidence': 0.7, 'scenario': scenario.value } return { 'alert': True, 'reason': detection_result['type'], 'confidence': detection_result['confidence'], 'scenario': scenario.value }
if __name__ == "__main__": filter_system = ScenarioAwareFilter() vehicle_data = { 'speed': 100, 'steering_angle': 2, 'acc_active': True, 'gear': 'D', 'turn_signal_left': False } scenario = filter_system.classify_scenario(vehicle_data) print(f"场景: {scenario.value}") detection = {'type': 'distraction', 'duration': 2.5, 'confidence': 0.8} gaze = (-45, 0) result = filter_system.filter_detection(detection, vehicle_data, gaze) print(f"过滤结果: {result}")
|