MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / _load_rlbench

Function _load_rlbench

visualize_benchmark_web.py:564–641  ·  view source on GitHub ↗

Load RLBench format data. Layout: images/frame_XXXX.png — RGB images depth/frame_XXXX.png — uint16 PNG depth (mm) pose/frame_XXXX.npy — per-frame 4x4 cam-to-world poses intrinsic/frame_XXXX.npy — per-frame 3x3 intrinsics (PyRep con

(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True)

Source from the content-addressed store, hash-verified

562
563
564def _load_rlbench(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True):
565 """Load RLBench format data.
566
567 Layout:
568 images/frame_XXXX.png — RGB images
569 depth/frame_XXXX.png — uint16 PNG depth (mm)
570 pose/frame_XXXX.npy — per-frame 4x4 cam-to-world poses
571 intrinsic/frame_XXXX.npy — per-frame 3x3 intrinsics (PyRep convention)
572 """
573 rgb_dir = scene_dir / "images"
574 depth_dir = scene_dir / "depth"
575 depth_mask_dir = scene_dir / "depth_mask"
576 pose_dir = scene_dir / "pose"
577 intrinsic_dir = scene_dir / "intrinsic"
578
579 rgb_paths = sorted(rgb_dir.glob("*.png"))
580 depth_paths = sorted(depth_dir.glob("*.png"))
581 depth_mask_paths = sorted(depth_mask_dir.glob("*.png")) if depth_mask_dir.exists() else []
582 pose_paths = sorted(pose_dir.glob("*.npy"))
583 intrinsic_paths = sorted(intrinsic_dir.glob("*.npy"))
584
585 # Use first frame's intrinsic as shared K for visualization (after abs correction)
586 K = np.load(str(intrinsic_paths[0])).astype(np.float32) if intrinsic_paths else np.eye(3, dtype=np.float32)
587 K[0, 0] = abs(K[0, 0])
588 K[1, 1] = abs(K[1, 1])
589
590 images, depths, extrinsics = [], [], []
591 for idx in frame_indices:
592 if idx >= len(rgb_paths) or idx >= len(depth_paths) or idx >= len(pose_paths):
593 continue
594
595 # RGB
596 img = cv2.imread(str(rgb_paths[idx]))
597 if img is not None:
598 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
599 else:
600 img = np.zeros((720, 1280, 3), dtype=np.uint8)
601
602 # Depth (uint16 mm -> metres)
603 d_raw = cv2.imread(str(depth_paths[idx]), cv2.IMREAD_ANYDEPTH)
604 if d_raw is not None:
605 depth = d_raw.astype(np.float32) / 1000.0
606 depth[~np.isfinite(depth)] = 0
607 # Apply depth mask if available
608 if use_depth_mask and depth_mask_paths and idx < len(depth_mask_paths):
609 mask = cv2.imread(str(depth_mask_paths[idx]), cv2.IMREAD_UNCHANGED)
610 if mask is not None:
611 depth[mask == 0] = 0
612 depth[depth > z_far] = 0
613 else:
614 depth = np.zeros((720, 1280), dtype=np.float32)
615
616 # Per-frame intrinsic: handle PyRep negative fx/fy by flipping image
617 K_frame = np.load(str(intrinsic_paths[idx])).astype(np.float32) if idx < len(intrinsic_paths) else K.copy()
618 if K_frame[0, 0] < 0:
619 img = img[:, ::-1, :].copy()
620 depth = depth[:, ::-1].copy()
621 K_frame[0, 2] = (img.shape[1] - 1) - K_frame[0, 2]

Callers

nothing calls this directly

Calls 2

loadMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected