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 220 221 222 223 224 225 226 227 228 229 230 231 232 233
| import numpy as np import cv2
class SensorSimulator: """传感器性能模拟器""" def __init__(self, sensor_type='IR'): """初始化 Args: sensor_type: 传感器类型 ('RGB', 'IR', 'RGB_IR') """ self.sensor_type = sensor_type def simulate_night_condition(self, image): """模拟夜间条件 Args: image: 输入图像 Returns: processed: 处理后的图像 """ if self.sensor_type == 'RGB': dark = image * 0.05 noise = np.random.normal(0, 30, image.shape).astype(np.int16) noisy = np.clip(dark.astype(np.int16) + noise, 0, 255).astype(np.uint8) return noisy elif self.sensor_type == 'IR': gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) if len(image.shape) == 3 else image normalized = cv2.equalizeHist(gray) return normalized elif self.sensor_type == 'RGB_IR': rgb_night = self.simulate_night_condition.__func__(type('obj', (), {'sensor_type': 'RGB'})(), image) ir_night = self.simulate_night_condition.__func__(type('obj', (), {'sensor_type': 'IR'})(), image) return ir_night def simulate_sunglasses(self, image, glasses_type='normal'): """模拟墨镜穿透 Args: image: 输入图像 glasses_type: 墨镜类型 Returns: visibility: 可见度 (0-1) """ penetration_rates = { 'RGB': { 'normal': 0.7, 'polarized': 0.6, 'ir_blocking': 0.5, 'metallic': 0.3 }, 'IR': { 'normal': 0.85, 'polarized': 0.75, 'ir_blocking': 0.4, 'metallic': 0.7 }, 'RGB_IR': { 'normal': 0.85, 'polarized': 0.75, 'ir_blocking': 0.5, 'metallic': 0.6 } } return penetration_rates[self.sensor_type].get(glasses_type, 0.5)
class DMSImageQualityAnalyzer: """DMS图像质量分析器""" def __init__(self): """初始化""" self.quality_metrics = {} def analyze_eye_visibility(self, image, eye_region): """分析眼部可见度 Args: image: 输入图像 eye_region: 眼部区域 (x, y, w, h) Returns: visibility_score: 可见度分数 (0-100) details: 详细指标 """ x, y, w, h = eye_region eye_roi = image[y:y+h, x:x+w] if eye_roi.size == 0: return 0, {} if len(eye_roi.shape) == 3: gray = cv2.cvtColor(eye_roi, cv2.COLOR_BGR2GRAY) else: gray = eye_roi contrast = gray.std() brightness = gray.mean() sharpness = cv2.Laplacian(gray, cv2.CV_64F).var() contrast_score = min(contrast / 40 * 40, 40) brightness_score = 40 - abs(brightness - 128) / 128 * 40 sharpness_score = min(sharpness / 100 * 20, 20) total_score = contrast_score + brightness_score + sharpness_score details = { 'contrast': contrast, 'brightness': brightness, 'sharpness': sharpness, 'contrast_score': contrast_score, 'brightness_score': brightness_score, 'sharpness_score': sharpness_score } return total_score, details
class SensorSelectionAdvisor: """传感器选型顾问""" DECISION_MATRIX = { 'economy': { 'recommendation': 'RGB', 'reason': '成本低,适合预算有限的项目', 'limitations': '夜间性能差,需要额外照明方案' }, 'standard': { 'recommendation': 'IR (850nm)', 'reason': '平衡成本与性能,Euro NCAP合规', 'limitations': '无色彩信息' }, 'premium': { 'recommendation': 'RGB-IR', 'reason': '全天候性能,最佳用户体验', 'limitations': '成本较高' }, 'luxury': { 'recommendation': 'RGB-IR + ToF', 'reason': '多模态融合,最高安全等级', 'limitations': '成本最高,算法复杂' } } def __init__(self): """初始化""" self.requirements = {} def set_requirements(self, budget='standard', night_driving=True, sunglasses_penetration=True, color_detection=False): """设置需求 Args: budget: 预算等级 night_driving: 夜间驾驶需求 sunglasses_penetration: 墨镜穿透需求 color_detection: 色彩检测需求 """ self.requirements = { 'budget': budget, 'night_driving': night_driving, 'sunglasses_penetration': sunglasses_penetration, 'color_detection': color_detection } def get_recommendation(self): """获取推荐方案 Returns: recommendation: 推荐结果 """ base_recommendation = self.DECISION_MATRIX[self.requirements['budget']] adjustments = [] if self.requirements['night_driving'] and base_recommendation['recommendation'] == 'RGB': adjustments.append('夜间驾驶需求建议升级到IR方案') if self.requirements['sunglasses_penetration']: if 'IR' not in base_recommendation['recommendation']: adjustments.append('墨镜穿透需求建议选择IR方案') if self.requirements['color_detection'] and base_recommendation['recommendation'] == 'IR': adjustments.append('色彩检测需求建议选择RGB-IR方案') return { 'recommendation': base_recommendation['recommendation'], 'reason': base_recommendation['reason'], 'limitations': base_recommendation['limitations'], 'adjustments': adjustments }
if __name__ == "__main__": advisor = SensorSelectionAdvisor() advisor.set_requirements( budget='standard', night_driving=True, sunglasses_penetration=True, color_detection=False ) result = advisor.get_recommendation() print(f"推荐方案: {result['recommendation']}") print(f"理由: {result['reason']}") print(f"限制: {result['limitations']}") ir_simulator = SensorSimulator('IR') rgb_simulator = SensorSimulator('RGB') print(f"\nIR墨镜穿透率: {ir_simulator.simulate_sunglasses(None, 'normal')*100:.0f}%") print(f"RGB墨镜穿透率: {rgb_simulator.simulate_sunglasses(None, 'normal')*100:.0f}%")
|