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
| """ 驾驶舱场景渲染配置
使用 Blender/Unreal Engine 渲染 """
import numpy as np from typing import Dict, List
class CockpitRenderer: """ 驾驶舱场景渲染器 生成 DMS/OMS 合成数据 """ def __init__(self): self.scene_config = { 'vehicle_model': 'sedan_2026', 'camera_position': 'steering_column', 'camera_fov': 60, 'resolution': (1920, 1080), 'frame_rate': 30 } self.driver_config = { 'gender': ['male', 'female'], 'age_range': (18, 70), 'ethnicity': ['asian', 'caucasian', 'african', 'hispanic'], 'body_type': ['slim', 'average', 'heavy'], 'height_range': (150, 200) } self.state_config = { 'fatigue_levels': ['alert', 'mild_fatigue', 'severe_fatigue', 'microsleep'], 'distraction_types': ['phone', 'navigation', 'eating', 'drinking', 'smoking', 'looking_away'], 'gaze_directions': ['front', 'left', 'right', 'down', 'up'], 'head_poses': ['front', 'yaw_left', 'yaw_right', 'pitch_down', 'pitch_up'] } self.environment_config = { 'lighting': ['daylight', 'dusk', 'night', 'tunnel', 'overcast'], 'weather': ['clear', 'rain', 'fog'], 'time_of_day': ['morning', 'afternoon', 'evening', 'night'] } def generate_dataset(self, num_samples: int) -> List[Dict]: """ 生成合成数据集 Args: num_samples: 样本数量 Returns: dataset: [ { 'image': np.ndarray, 'landmarks': np.ndarray, 'gaze': tuple, 'state': dict, 'metadata': dict } ] """ dataset = [] for i in range(num_samples): driver = self._sample_driver() state = self._sample_state() environment = self._sample_environment() image = self._render_image(driver, state, environment) landmarks = self._generate_landmarks(driver, state) gaze = self._generate_gaze(state) sample = { 'image': image, 'landmarks': landmarks, 'gaze': gaze, 'state': state, 'metadata': { 'driver_id': i, 'driver_config': driver, 'environment': environment } } dataset.append(sample) return dataset def _sample_driver(self) -> Dict: """随机采样驾驶员配置""" return { 'gender': np.random.choice(self.driver_config['gender']), 'age': np.random.randint(*self.driver_config['age_range']), 'ethnicity': np.random.choice(self.driver_config['ethnicity']), 'body_type': np.random.choice(self.driver_config['body_type']), 'height': np.random.randint(*self.driver_config['height_range']), 'accessories': self._sample_accessories() } def _sample_accessories(self) -> Dict: """采样配饰(墨镜、口罩等)""" return { 'sunglasses': np.random.choice([True, False], p=[0.3, 0.7]), 'mask': np.random.choice([True, False], p=[0.2, 0.8]), 'hat': np.random.choice([True, False], p=[0.1, 0.9]), 'glasses': np.random.choice([True, False], p=[0.4, 0.6]) } def _sample_state(self) -> Dict: """采样驾驶员状态""" return { 'fatigue_level': np.random.choice(self.state_config['fatigue_levels']), 'distraction_type': np.random.choice(self.state_config['distraction_types']), 'gaze_direction': np.random.choice(self.state_config['gaze_directions']), 'head_pose': np.random.choice(self.state_config['head_poses']) } def _sample_environment(self) -> Dict: """采样环境条件""" return { 'lighting': np.random.choice(self.environment_config['lighting']), 'weather': np.random.choice(self.environment_config['weather']), 'time_of_day': np.random.choice(self.environment_config['time_of_day']) } def _render_image(self, driver, state, environment) -> np.ndarray: """ 渲染图像 实际实现需要调用 Blender/Unreal Engine API """ return np.random.randint(0, 255, (1080, 1920, 3), dtype=np.uint8) def _generate_landmarks(self, driver, state) -> np.ndarray: """ 生成面部关键点标注 基于 3D 模型自动生成 """ landmarks = np.random.rand(68, 2) * 1000 return landmarks def _generate_gaze(self, state) -> tuple: """生成视线方向""" gaze_map = { 'front': (0, 0, 1), 'left': (-30, 0, 1), 'right': (30, 0, 1), 'down': (0, -30, 1), 'up': (0, 30, 1) } return gaze_map.get(state['gaze_direction'], (0, 0, 1))
if __name__ == "__main__": renderer = CockpitRenderer() dataset = renderer.generate_dataset(100) print(f"生成样本数: {len(dataset)}") print(f"样本示例: {dataset[0]['metadata']}")
|