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
| import numpy as np
class VisionOnlyBlindSpot: """纯视觉 DMS/OMS 盲区分析""" def __init__(self, cabin_config: dict): self.camera_pos = cabin_config.get('camera_pos', [0.5, 0.8, 1.2]) self.fov_h = cabin_config.get('fov_h', 120) self.fov_v = cabin_config.get('fov_v', 60) self.resolution = cabin_config.get('resolution', (1920, 1080)) def check_occlusion(self, target_pos: np.ndarray, obstacles: list) -> bool: """ 检查目标是否被遮挡 Args: target_pos: 目标3D位置 [x, y, z] (米) obstacles: 障碍物列表 [{"type": "seatback", "height": 0.7, "pos": [0.3, 0.5, 0.8]}] Returns: True if occluded, False if visible """ direction = np.array(target_pos) - np.array(self.camera_pos) direction_normalized = direction / np.linalg.norm(direction) for obs in obstacles: obs_pos = np.array(obs['pos']) obs_to_camera = obs_pos - np.array(self.camera_pos) proj = np.dot(obs_to_camera, direction_normalized) if proj <= 0 or proj > np.linalg.norm(direction): continue perp_dist = np.linalg.norm(obs_to_camera - proj * direction_normalized) if perp_dist < obs.get('height', 0.3): return True return False def analyze_cabin_coverage(self): """分析座舱覆盖率""" rear_passenger_pos = [0.3, 0.4, 0.5] obstacles = [ {"type": "front_seatback", "height": 0.35, "pos": [0.4, 0.5, 0.7]}, {"type": "headrest", "height": 0.15, "pos": [0.4, 0.6, 0.9]}, ] is_occluded = self.check_occlusion(rear_passenger_pos, obstacles) scenarios = { "前排驾驶员": False, "前排乘客": False, "后排成人(正常坐姿)": True, "后排儿童(安全座椅)": True, "脚部空间": True, "毯子覆盖乘员": True, } coverage = sum(1 for v in scenarios.values() if not v) / len(scenarios) print(f"纯视觉方案座舱覆盖率: {coverage*100:.0f}%") print(f"盲区场景: {[k for k, v in scenarios.items() if v]}") return coverage
config = { 'camera_pos': [0.5, 0.8, 1.2], 'fov_h': 120, 'fov_v': 60, 'resolution': (1920, 1080) }
analyzer = VisionOnlyBlindSpot(config) analyzer.analyze_cabin_coverage()
|