File size: 1,277 Bytes
6da4e64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Materialize the explicitly selected COLMAP model for consumers expecting sparse/0."""
import argparse
import json
from pathlib import Path
import shutil
import pycolmap


def export_selected(run):
    record = json.loads((run / "colmap-run.json").read_text(encoding="utf-8"))
    model_id = int(record["selected_model"])
    source = run / "sparse" / str(model_id)
    reconstruction = pycolmap.Reconstruction(source)
    if len(reconstruction.images) != record["registered_images"]:
        raise ValueError("Selected model and registration record disagree")
    destination = run / "selected"
    destination.mkdir(exist_ok=False)
    sparse = destination / "sparse/0"
    sparse.mkdir(parents=True)
    reconstruction.write(sparse)
    shutil.copytree(run / "images", destination / "images")
    (destination / "selection.json").write_text(json.dumps({
        "source_model": model_id, "registered_images": len(reconstruction.images),
        "source_run": str(run.resolve()), "scope": "Canonical layout, no geometry changes"}, indent=2), encoding="utf-8")
    print(destination)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("run", type=Path)
    args = parser.parse_args()
    export_selected(args.run)