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

Function _load_droid_style

visualize_benchmark_web.py:215–276  ·  view source on GitHub ↗

Load DROID-style data (shared by droid, tum, bonn, nrgbd, 7scenes, tanks). pose_scale: multiplier for pose translation. 1.0 (default) for most datasets. 0.001 for DTU where poses are in mm but depth /1000 converts to meters.

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

Source from the content-addressed store, hash-verified

213
214
215def _load_droid_style(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True, pose_scale: float = 1.0):
216 """Load DROID-style data (shared by droid, tum, bonn, nrgbd, 7scenes, tanks).
217
218 pose_scale: multiplier for pose translation. 1.0 (default) for most datasets.
219 0.001 for DTU where poses are in mm but depth /1000 converts to meters.
220 """
221 rgb_dir = scene_dir / "images" / "left"
222 depth_dir = scene_dir / "depth_npy"
223 depth_mask_dir = scene_dir / "depth_mask"
224
225 rgb_paths = sorted(rgb_dir.glob("*.png"), key=lambda p: int(p.stem))
226 depth_paths = sorted(depth_dir.glob("*.png"), key=lambda p: int(p.stem.replace("_depth", "")))
227 depth_mask_paths = sorted(depth_mask_dir.glob("*.png")) if depth_mask_dir.exists() else []
228
229 # Poses
230 pose_path = scene_dir / "poses_ma" / "poses_depth_ba.npy"
231 if not pose_path.exists():
232 pose_path = scene_dir / "poses_ma" / "poses.npy"
233 all_poses = np.load(str(pose_path)).astype(np.float32)
234 print(f"using pose from {pose_path}")
235
236 # Intrinsics
237 intr_dir = scene_dir / "intrinsics"
238 K_path = list(intr_dir.glob("*left.npy")) or list(intr_dir.glob("*.npy"))
239 K = np.load(str(K_path[0])).astype(np.float32) if K_path else np.eye(3, dtype=np.float32)
240
241 images, depths, extrinsics = [], [], []
242 for idx in frame_indices:
243 if idx >= len(rgb_paths) or idx >= len(depth_paths):
244 continue
245 # RGB
246 img = cv2.imread(str(rgb_paths[idx]))
247 if img is not None:
248 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
249 else:
250 img = np.zeros((480, 640, 3), dtype=np.uint8)
251
252 # Depth
253 d_raw = cv2.imread(str(depth_paths[idx]), cv2.IMREAD_UNCHANGED)
254 if d_raw is not None:
255 depth = d_raw.astype(np.float32) / 1000.0
256 depth[~np.isfinite(depth)] = 0
257 # Apply depth mask if available
258 if use_depth_mask and depth_mask_paths and idx < len(depth_mask_paths):
259 mask = cv2.imread(str(depth_mask_paths[idx]), cv2.IMREAD_UNCHANGED)
260 if mask is not None:
261 depth[mask == 0] = 0
262 depth[depth > z_far] = 0
263 else:
264 depth = np.zeros((480, 640), dtype=np.float32)
265
266 images.append(img)
267 depths.append(depth)
268 pose = all_poses[min(idx, len(all_poses) - 1)].copy()
269 if pose_scale != 1.0:
270 pose[:3, 3] *= pose_scale
271 extrinsics.append(pose)
272

Callers

nothing calls this directly

Calls 2

loadMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected