Load RoboTwin format data. Layout: camera_data/images/*.png — RGB images camera_data/depths/*.png — uint16 PNG depth (mm) camera_data/extrinsics/*.npy — per-frame 3x4 cam-to-world poses camera_data/intrinsics/*.npy — per-frame 3x3 intrinsics
(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True)
| 451 | |
| 452 | |
| 453 | def _load_robotwin(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True): |
| 454 | """Load RoboTwin format data. |
| 455 | |
| 456 | Layout: |
| 457 | camera_data/images/*.png — RGB images |
| 458 | camera_data/depths/*.png — uint16 PNG depth (mm) |
| 459 | camera_data/extrinsics/*.npy — per-frame 3x4 cam-to-world poses |
| 460 | camera_data/intrinsics/*.npy — per-frame 3x3 intrinsics |
| 461 | """ |
| 462 | rgb_dir = scene_dir / "camera_data" / "images" |
| 463 | depth_dir = scene_dir / "camera_data" / "depths" |
| 464 | depth_mask_dir = scene_dir / "depth_mask" |
| 465 | extrinsic_dir = scene_dir / "camera_data" / "extrinsics" |
| 466 | intrinsic_dir = scene_dir / "camera_data" / "intrinsics" |
| 467 | |
| 468 | rgb_paths = sorted(rgb_dir.glob("*.png")) |
| 469 | depth_paths = sorted(depth_dir.glob("*.png")) |
| 470 | depth_mask_paths = sorted(depth_mask_dir.glob("*.png")) if depth_mask_dir.exists() else [] |
| 471 | extrinsic_paths = sorted(extrinsic_dir.glob("*.npy")) |
| 472 | intrinsic_paths = sorted(intrinsic_dir.glob("*.npy")) |
| 473 | |
| 474 | # Use first frame's intrinsic as shared K (they are typically identical) |
| 475 | K = np.load(str(intrinsic_paths[0])).astype(np.float32) if intrinsic_paths else np.eye(3, dtype=np.float32) |
| 476 | |
| 477 | images, depths, extrinsics = [], [], [] |
| 478 | for idx in frame_indices: |
| 479 | if idx >= len(rgb_paths) or idx >= len(depth_paths) or idx >= len(extrinsic_paths): |
| 480 | continue |
| 481 | |
| 482 | # RGB |
| 483 | img = cv2.imread(str(rgb_paths[idx])) |
| 484 | if img is not None: |
| 485 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
| 486 | else: |
| 487 | img = np.zeros((720, 1280, 3), dtype=np.uint8) |
| 488 | |
| 489 | # Depth (uint16 mm -> metres) |
| 490 | d_raw = cv2.imread(str(depth_paths[idx]), cv2.IMREAD_ANYDEPTH) |
| 491 | if d_raw is not None: |
| 492 | depth = d_raw.astype(np.float32) / 1000.0 |
| 493 | depth[~np.isfinite(depth)] = 0 |
| 494 | # Apply depth mask if available |
| 495 | if use_depth_mask and depth_mask_paths and idx < len(depth_mask_paths): |
| 496 | mask = cv2.imread(str(depth_mask_paths[idx]), cv2.IMREAD_UNCHANGED) |
| 497 | if mask is not None: |
| 498 | depth[mask == 0] = 0 |
| 499 | depth[depth > z_far] = 0 |
| 500 | else: |
| 501 | depth = np.zeros((720, 1280), dtype=np.float32) |
| 502 | |
| 503 | # Pose (3x4 cam-to-world) |
| 504 | pose = np.load(str(extrinsic_paths[idx])).astype(np.float32) |
| 505 | if pose.shape == (4, 4): |
| 506 | pose = pose[:3, :] |
| 507 | |
| 508 | images.append(img) |
| 509 | depths.append(depth) |
| 510 | extrinsics.append(pose) |