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
| """ TSR摄像头复用架构:限速牌识别+驾驶员状态监测 降低硬件成本,符合Euro NCAP多任务要求 """
from typing import Tuple, Optional import numpy as np
class TSRDMSCameraFusion: """TSR+DMS摄像头融合系统""" def __init__(self): self.tsr_camera_config = { "resolution": (1920, 1080), "fov_degree": 45, "fps": 30, "position": "前挡风玻璃中部" } self.dms_camera_config = { "resolution": (1600, 1200), "fov_degree": 60, "fps": 30, "position": "仪表盘/A柱", "ir_wavelength_nm": 940 } def detect_speed_limit(self, image: np.ndarray) -> Tuple[int, float]: """ TSR限速牌检测 Args: image: 前视摄像头图像 Returns: (限速值, 置信度) """ detected_limit = np.random.choice([30, 50, 60, 80, 100, 120, 130]) confidence = np.random.uniform(0.85, 0.99) return detected_limit, confidence def detect_driver_state(self, image: np.ndarray) -> Tuple[str, float]: """ DMS驾驶员状态检测 Args: image: DMS红外摄像头图像 Returns: (状态, 置信度) """ state = np.random.choice(["正常", "轻度疲劳", "重度疲劳", "分心"]) confidence = np.random.uniform(0.80, 0.95) return state, confidence def adjust_warning_threshold(self, speed_limit: int, driver_state: str) -> dict: """ 根据限速和驾驶员状态调整警告阈值 Args: speed_limit: 当前限速 driver_state: 驾驶员状态 Returns: dict: 调整后的阈值配置 """ base_threshold = { "distraction_seconds": 3.0, "perclos_percent": 30, "warning_level": "一级" } if speed_limit <= 50: base_threshold["distraction_seconds"] = 2.0 base_threshold["warning_level"] = "二级" elif speed_limit >= 120: base_threshold["distraction_seconds"] = 4.0 if driver_state == "轻度疲劳": base_threshold["distraction_seconds"] *= 0.8 base_threshold["perclos_percent"] = 25 elif driver_state == "重度疲劳": base_threshold["distraction_seconds"] = 1.0 base_threshold["warning_level"] = "三级" elif driver_state == "分心": base_threshold["distraction_seconds"] *= 0.7 return base_threshold def process_frame(self, tsr_image: np.ndarray, dms_image: np.ndarray) -> dict: """ 处理单帧数据:融合TSR+DMS Args: tsr_image: 前视摄像头帧 dms_image: DMS红外摄像头帧 Returns: dict: 融合处理结果 """ speed_limit, tsr_confidence = self.detect_speed_limit(tsr_image) driver_state, dms_confidence = self.detect_driver_state(dms_image) warning_threshold = self.adjust_warning_threshold(speed_limit, driver_state) return { "speed_limit": speed_limit, "tsr_confidence": tsr_confidence, "driver_state": driver_state, "dms_confidence": dms_confidence, "warning_threshold": warning_threshold }
if __name__ == "__main__": fusion_system = TSRDMSCameraFusion() tsr_frame = np.random.randint(0, 255, (1080, 1920, 3), dtype=np.uint8) dms_frame = np.random.randint(0, 255, (1200, 1600, 1), dtype=np.uint8) result = fusion_system.process_frame(tsr_frame, dms_frame) print("TSR+DMS融合检测结果:") print(f" 限速: {result['speed_limit']} km/h (置信度: {result['tsr_confidence']:.2f})") print(f" 驾驶员状态: {result['driver_state']} (置信度: {result['dms_confidence']:.2f})") print(f" 警告阈值: {result['warning_threshold']}")
|