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
| class GazeToCameraMapper: """ Toyota专利核心:将驾驶员视线方向映射到车外摄像头 工作流程: 1. DMS摄像头检测驾驶员眼球方向(方位角+俯仰角) 2. 将眼球方向转换为车外世界坐标 3. 选择最匹配方向的车外摄像头 4. 该摄像头拍摄照片 5. 根据视线精确角度裁剪照片 """ EXTERIOR_CAMERAS = { 'front_left': {'azimuth': -30, 'elevation': 0}, 'front_center': {'azimuth': 0, 'elevation': 0}, 'front_right': {'azimuth': 30, 'elevation': 0}, 'left': {'azimuth': -90, 'elevation': 0}, 'right': {'azimuth': 90, 'elevation': 0}, 'rear_left': {'azimuth': -150, 'elevation': 0}, 'rear_center': {'azimuth': 180, 'elevation': 0}, 'rear_right': {'azimuth': 150, 'elevation': 0}, } def __init__(self): self.gaze_tracker = None def map_gaze_to_camera(self, gaze_azimuth: float, gaze_elevation: float) -> tuple: """ 将视线方向映射到最佳车外摄像头 Args: gaze_azimuth: 视线方位角(度),0=正前,正值向右 gaze_elevation: 视线俯仰角(度),0=水平,正=向上 Returns: (camera_name, offset_deg): 最佳摄像头和偏移角度 """ best_camera = None best_diff = float('inf') for cam_name, cam_angle in self.EXTERIOR_CAMERAS.items(): diff = abs(gaze_azimuth - cam_angle['azimuth']) if diff < best_diff: best_diff = diff best_camera = cam_name return best_camera, best_diff def capture_gaze_target(self, gaze_data: dict) -> dict: """ 捕获驾驶员视线所及的目标 Args: gaze_data: { 'azimuth': 方位角, 'elevation': 俯仰角, 'confidence': 置信度, 'both_eyes': 是否双眼一致 } Returns: { 'camera': 摄像头名称, 'image': 拍摄的图像, 'gaze_point': 视线在图像中的落点, 'location': GPS位置, 'timestamp': 时间戳 } """ if gaze_data['confidence'] < 0.5: return {'error': 'low_confidence', 'gaze': gaze_data} cam_name, offset = self.map_gaze_to_camera( gaze_data['azimuth'], gaze_data['elevation'] ) image = self._trigger_capture(cam_name) gaze_point = self._compute_gaze_point( gaze_data['azimuth'], gaze_data['elevation'], cam_name ) cropped = self._crop_around_gaze(image, gaze_point) return { 'camera': cam_name, 'image': cropped, 'gaze_point': gaze_point, 'location': self._get_gps(), 'timestamp': self._get_timestamp(), 'gaze_offset_deg': offset }
|