File size: 2,239 Bytes
d632e09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""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()