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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
| """ NVIDIA Isaac Sim 座舱数据合成管道
依赖: Isaac Sim 5.0 (pip install isaacsim) 文档: https://docs.isaacsim.omniverse.nvidia.com/
用途: 生成DMS/OMS训练数据 - 驾驶员姿态变化(正常/疲劳/分心/OOP) - 多光照条件(白天/夜晚/隧道/逆光) - 多人体体型(不同身高/体重/性别) - 红外+RGB同步采集 """
import numpy as np from typing import Dict, List, Tuple import json
class CabinDataSynthesisConfig: """ 座舱数据合成配置 定义所有变化维度以确保数据多样性 """ DRIVER_BODY_TYPES = { 'small_female': {'height': 1.50, 'weight': 45, 'bmi': 20.0}, 'medium_female': {'height': 1.62, 'weight': 55, 'bmi': 20.9}, 'large_female': {'height': 1.75, 'weight': 75, 'bmi': 24.5}, 'small_male': {'height': 1.65, 'weight': 60, 'bmi': 22.0}, 'medium_male': {'height': 1.78, 'weight': 78, 'bmi': 24.6}, 'large_male': {'height': 1.90, 'weight': 95, 'bmi': 26.3}, 'obese': {'height': 1.75, 'weight': 110, 'bmi': 35.9}, } BEHAVIOR_STATES = { 'normal': { 'head_pose': 'forward', 'gaze': 'road_ahead', 'body_pose': 'upright', 'hands': 'steering_wheel', 'blink_rate': 15, 'duration': 30, }, 'fatigue_mild': { 'head_pose': 'slight_tilt', 'gaze': 'unfocused', 'body_pose': 'slight_slouch', 'hands': 'steering_wheel', 'blink_rate': 25, 'eye_openness': 0.7, 'duration': 30, }, 'fatigue_severe': { 'head_pose': 'nodding', 'gaze': 'closing_eyes', 'body_pose': 'deep_slouch', 'hands': 'loose_grip', 'blink_rate': 40, 'eye_openness': 0.4, 'perclos': 0.3, 'duration': 30, }, 'distraction_phone': { 'head_pose': 'down_right', 'gaze': 'lap', 'body_pose': 'leaning_forward', 'hands': 'right_hand_off_wheel', 'phone_visible': True, 'duration': 15, }, 'distraction_reach': { 'head_pose': 'right', 'gaze': 'passenger_seat', 'body_pose': 'twisted', 'hands': 'right_hand_reaching', 'duration': 10, }, 'oop_forward': { 'head_pose': 'on_wheel', 'gaze': 'closed', 'body_pose': 'forward_bent', 'hands': 'on_wheel', 'eye_openness': 0.0, 'duration': 10, }, 'oop_side': { 'head_pose': 'left_tilt_45', 'gaze': 'closed', 'body_pose': 'lateral_bent', 'hands': 'off_wheel', 'duration': 10, }, } LIGHTING_CONDITIONS = { 'day_clear': { 'sun_elevation': 45, 'sun_intensity': 80000, 'color_temp': 6500, 'shadows': True, 'env_map': 'sky_clear.hdr', }, 'day_overcast': { 'sun_elevation': 30, 'sun_intensity': 20000, 'color_temp': 7500, 'shadows': False, 'env_map': 'sky_overcast.hdr', }, 'sunset': { 'sun_elevation': 5, 'sun_intensity': 3000, 'color_temp': 2800, 'shadows': True, 'env_map': 'sky_sunset.hdr', }, 'night_urban': { 'sun_elevation': -10, 'sun_intensity': 0, 'street_lights': True, 'ir_illumination': True, 'ir_intensity': 0.8, 'env_map': 'night_urban.hdr', }, 'tunnel': { 'sun_elevation': 0, 'sun_intensity': 0, 'tunnel_lights': True, 'color_temp': 4000, 'ir_illumination': True, 'ir_intensity': 1.0, }, 'backlit': { 'sun_elevation': 15, 'sun_intensity': 60000, 'sun_direction': 'behind_driver', 'shadows': True, 'high_dynamic_range': True, }, } CAMERA_CONFIGS = { 'dms_standard': { 'position': [0.15, -0.8, 0.35], 'rotation': [0, 0, 0], 'fov': 60, 'resolution': [1280, 800], 'fps': 30, 'type': 'rgb_ir', 'ir_wavelength': 940, }, 'dms_wide': { 'position': [0.0, -1.2, 0.4], 'rotation': [0, 0, 0], 'fov': 90, 'resolution': [1920, 1080], 'fps': 30, 'type': 'rgb', }, 'oms_passenger': { 'position': [-0.3, -0.8, 0.35], 'rotation': [0, 15, 0], 'fov': 75, 'resolution': [1280, 800], 'fps': 25, 'type': 'rgb_ir', }, } def generate_dataset_spec(self) -> Dict: """生成完整数据集规格""" total_scenarios = ( len(self.DRIVER_BODY_TYPES) * len(self.BEHAVIOR_STATES) * len(self.LIGHTING_CONDITIONS) * len(self.CAMERA_CONFIGS) ) return { 'total_combinations': total_scenarios, 'body_types': len(self.DRIVER_BODY_TYPES), 'behaviors': len(self.BEHAVIOR_STATES), 'lighting': len(self.LIGHTING_CONDITIONS), 'cameras': len(self.CAMERA_CONFIGS), 'est_images': total_scenarios * 900, 'est_size_gb': total_scenarios * 900 * 2 / 1024, }
ISAAC_SIM_SCRIPT = ''' # from isaacsim import SimulationApp # sim_app = SimulationApp({"headless": True}) # # import omni.replicator.core as rep # from pxr import Usd, UsdGeom # # # 创建座舱场景 # def create_cabin_scene(config): # """加载座舱USD场景""" # stage = omni.usd.get_context().get_stage() # # # 加载车辆座舱模型 # cabin_path = "/World/Cabin" # omni.kit.commands.execute( # "ReferencePayload", # path_to=cabin_path, # asset_path="/data/cabin_interior.usd" # ) # # # 配置光照 # dist_light = stage.GetPrimAtPath("/World/Cabin/DistantLight") # dist_light.GetAttribute("intensity").Set(config['sun_intensity']) # dist_light.GetAttribute("color").Set( # _color_temp_to_rgb(config['color_temp']) # ) # # # IR补光(通过自定义灯光) # if config.get('ir_illumination'): # ir_light = stage.DefinePrim("/World/Cabin/IRLight", "DistantLight") # ir_light.GetAttribute("intensity").Set(config['ir_intensity'] * 1000) # ir_light.GetAttribute("color").Set((1, 0.1, 0.1)) # 近似红外 # # return stage # # # 驾驶员姿态控制 # def set_driver_pose(skel_prim, pose_config): # """设置驾驶员骨骼姿态""" # # 头部旋转 # head = skel_prim.GetPrimChild("head") # head.GetAttribute("xformOp:rotateXYZ").Set( # pose_config.get('head_rotation', (0, 0, 0)) # ) # # 眼睑开度 # for eye in ['left_eye', 'right_eye']: # eye_prim = skel_prim.GetPrimChild(eye) # eye_prim.GetAttribute("openness").Set( # pose_config.get('eye_openness', 1.0) # ) # # # 域随机化 # def apply_domain_randomization(): # """Omniverse Replicator域随机化""" # with rep.randomize: # # 材质随机化 # rep.material.albedo( # texture=rep.choice([ # "/data/materials/leather_black.png", # "/data/materials/leather_brown.png", # "/data/materials/fabric_gray.png", # ]) # ) # # 光照抖动 # rep.lighting.intensity( # rep.distribution.normal(80000, 5000) # ) # # 相机微抖动 # rep.camera.rotation( # rep.distribution.uniform(-2, 2) # ) # # # 数据生成主循环 # def generate_cabin_dataset(config): # """生成完整座舱数据集""" # for body_type in config.DRIVER_BODY_TYPES: # for behavior in config.BEHAVIOR_STATES: # for lighting in config.LIGHTING_CONDITIONS: # for camera in config.CAMERA_CONFIGS: # # 设置场景 # create_cabin_scene(lighting) # # 加载人体模型 # skel = load_metahuman(body_type) # set_driver_pose(skel, behavior) # # 域随机化 # apply_domain_randomization() # # 渲染 # rep.orchestrator.run() # # 保存数据 # save_annotations() '''
class AnnotationFormat: """ Isaac Sim自动标注输出格式 """ @staticmethod def bounding_box(x, y, w, h, label, confidence=1.0): """YOLO格式边界框""" return { 'class': label, 'bbox': [x, y, w, h], 'confidence': confidence, 'format': 'yolo' } @staticmethod def keypoint_annotation(keypoints: List[Tuple[float, float, float]]): """面部关键点标注""" labels = [ 'left_eye', 'right_eye', 'nose_tip', 'mouth_left', 'mouth_right', 'left_ear', 'right_ear', 'chin', 'forehead' ] return [ {'label': labels[i], 'position': kp, 'confidence': 1.0} for i, kp in enumerate(keypoints) ] @staticmethod def semantic_segmentation(classes: Dict[str, int]): """语义分割标注""" return { 'driver_face': classes.get('face', 1), 'driver_hands': classes.get('hands', 2), 'steering_wheel': classes.get('steering_wheel', 3), 'dashboard': classes.get('dashboard', 4), 'seat': classes.get('seat', 5), 'phone': classes.get('phone', 6), 'background': 0, }
if __name__ == "__main__": config = CabinDataSynthesisConfig() spec = config.generate_dataset_spec() print("=== 座舱数据合成规格 ===") print(f"体型数: {spec['body_types']}") print(f"行为状态数: {spec['behaviors']}") print(f"光照条件数: {spec['lighting']}") print(f"相机配置数: {spec['cameras']}") print(f"总场景组合: {spec['total_combinations']}") print(f"预计图片数: {spec['est_images']:,}") print(f"预计大小: {spec['est_size_gb']:.1f} GB") print("\n=== 行为状态详情 ===") for state, params in config.BEHAVIOR_STATES.items(): print(f" {state}: head={params.get('head_pose')}, " f"gaze={params.get('gaze')}") print("\n=== 光照条件详情 ===") for cond, params in config.LIGHTING_CONDITIONS.items(): print(f" {cond}: intensity={params.get('sun_intensity', 0)} lux, " f"IR={'Yes' if params.get('ir_illumination') else 'No'}")
|