| |
| """Locate and optionally load one synchronized Real4D frame.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| from pathlib import Path |
|
|
|
|
| def frame_paths(root: Path, subset: str, scene: str, trajectory: str, index: int): |
| if not 0 <= index < 300: |
| raise ValueError("frame index must be in [0, 299]") |
| scene_dir = root / subset / scene |
| number = index + 1 |
| stem = f"{trajectory}_{number:06d}" |
| rgb = scene_dir / "images" / trajectory / f"{stem}.jpg" |
| depth = scene_dir / "depths" / trajectory / f"{stem}.jpg.geometric.png" |
| camera_json = scene_dir / "camera_params" / f"{trajectory}.json" |
| with camera_json.open("r", encoding="utf-8") as handle: |
| camera = json.load(handle)[index] |
| return rgb, depth, camera |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser(description=__doc__) |
| parser.add_argument("root", type=Path, help="Real4D dataset root") |
| parser.add_argument("subset", choices=("dynerf", "meetroom")) |
| parser.add_argument("scene") |
| parser.add_argument("trajectory", help="for example cam00_01") |
| parser.add_argument("index", type=int, help="zero-based frame index [0, 299]") |
| parser.add_argument( |
| "--inspect-depth", |
| action="store_true", |
| help="print depth range; requires Pillow and NumPy", |
| ) |
| args = parser.parse_args() |
|
|
| rgb, depth, camera = frame_paths( |
| args.root.resolve(), args.subset, args.scene, args.trajectory, args.index |
| ) |
| for path in (rgb, depth): |
| if not path.is_file(): |
| raise FileNotFoundError(path) |
|
|
| print(f"RGB: {rgb}") |
| print(f"Depth: {depth}") |
| print("Camera:") |
| print(json.dumps(camera, indent=2)) |
|
|
| if args.inspect_depth: |
| import numpy as np |
| from PIL import Image |
|
|
| depth_mm = np.asarray(Image.open(depth), dtype=np.uint16) |
| valid = depth_mm > 0 |
| if valid.any(): |
| values_m = depth_mm[valid].astype(np.float32) / 1000.0 |
| print( |
| f"Valid depth: {valid.mean():.2%}; " |
| f"range: [{values_m.min():.3f}, {values_m.max():.3f}] m" |
| ) |
| else: |
| print("Valid depth: 0%") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|
|
|