Download projects/spatial-0/scripts/export_colmap_selection.py from KineJIng/kinejing-open-source: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/datasets/KineJIng/kinejing-open-source/resolve/main/projects/spatial-0/scripts/export_colmap_selection.py
- Command line
-
hf download hf://datasets/KineJIng/kinejing-open-source/projects/spatial-0/scripts/export_colmap_selection.py
-
curl -L -o export_colmap_selection.py https://huggingface.co/datasets/KineJIng/kinejing-open-source/resolve/main/projects/spatial-0/scripts/export_colmap_selection.py
1.28 kB
| """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) | |