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

Function _load_ropedia

visualize_benchmark_web.py:279–385  ·  view source on GitHub ↗

Load Ropedia/ViPE format data.

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

Source from the content-addressed store, hash-verified

277
278
279def _load_ropedia(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True, conf_threshold: float = 0.0):
280 """Load Ropedia/ViPE format data."""
281 rgb_dir = scene_dir / "images" / "left"
282 # Prefer depths_ropedia/ (raw), fall back to depths/ (cleaned)
283 depth_dir = scene_dir / "depths_ropedia"
284 if not depth_dir.exists():
285 depth_dir = scene_dir / "depths"
286 depth_mask_dir = scene_dir / "depth_mask"
287 conf_mask_dir = scene_dir / "conf_mask"
288 has_conf = conf_mask_dir.is_dir()
289
290 rgb_paths = sorted(rgb_dir.glob("*.png"))
291 depth_paths = sorted(depth_dir.glob("*.png"))
292 depth_mask_paths = sorted(depth_mask_dir.glob("*.png")) if depth_mask_dir.exists() else []
293
294 # Try loading poses: prefer pose/ (refined), fall back to pose_from_hdf5/
295 pose_file = scene_dir / "pose" / "left.npz"
296 if not pose_file.exists():
297 pose_file = scene_dir / "pose_from_hdf5" / "left.npz"
298 pose_data = np.load(str(pose_file))
299 all_poses = pose_data["data"].astype(np.float32)
300 pose_inds = pose_data.get("inds", None)
301 if all_poses.ndim == 3 and all_poses.shape[1] == 4 and all_poses.shape[2] == 4:
302 all_poses = all_poses[:, :3, :]
303
304 # Intrinsics: read from annotation.hdf5 if available, else hardcode
305 ann_path = scene_dir / "annotation.hdf5"
306 if ann_path.exists():
307 with h5py.File(str(ann_path), "r") as f:
308 k_vals = f["calibration/cam01/K"][:].tolist() # [fx, fy, cx, cy]
309 K = np.array([[k_vals[0], 0, k_vals[2]],
310 [0, k_vals[1], k_vals[3]],
311 [0, 0, 1]], dtype=np.float32)
312 else:
313 K = np.array([[200, 0, 256], [0, 200, 256], [0, 0, 1]], dtype=np.float32)
314
315 images, depths, extrinsics = [], [], []
316 for idx in frame_indices:
317 if idx >= len(all_poses):
318 continue
319
320 # Determine file names based on pose_inds if available
321 if pose_inds is not None and idx < len(pose_inds):
322 rgb_fname = f"frame_{int(pose_inds[idx]):05d}_rgb.png"
323 depth_fname = f"{int(pose_inds[idx]):06d}.png"
324 else:
325 rgb_fname = None
326 depth_fname = None
327
328 # RGB
329 if rgb_fname and (rgb_dir / rgb_fname).exists():
330 img = cv2.cvtColor(cv2.imread(str(rgb_dir / rgb_fname)), cv2.COLOR_BGR2RGB)
331 elif idx < len(rgb_paths):
332 img = cv2.cvtColor(cv2.imread(str(rgb_paths[idx])), cv2.COLOR_BGR2RGB)
333 else:
334 continue
335
336 # Depth

Callers

nothing calls this directly

Calls 2

loadMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected