test: cover COLMAP manifest import
Browse files- tests/test_import_colmap.py +36 -0
tests/test_import_colmap.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
from import_colmap import import_colmap
|
| 4 |
+
from validate_capture_manifest import validate_capture_manifest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_import_colmap_builds_valid_world_to_camera_manifest(tmp_path):
|
| 8 |
+
(tmp_path / "images").mkdir(exist_ok=True)
|
| 9 |
+
(tmp_path / "images" / "one.png").write_bytes(b"one")
|
| 10 |
+
(tmp_path / "images" / "two.png").write_bytes(b"two")
|
| 11 |
+
cameras = tmp_path / "cameras.txt"
|
| 12 |
+
cameras.write_text("# Camera list\n1 PINHOLE 640 480 500 500 320 240\n", encoding="utf-8")
|
| 13 |
+
images = tmp_path / "images.txt"
|
| 14 |
+
images.write_text("\n".join([
|
| 15 |
+
"# Images", "1 1 0 0 0 0 0 0 1 images/one.png", "", "2 1 0 0 0 -1 0 0 1 images/two.png", "",
|
| 16 |
+
]), encoding="utf-8")
|
| 17 |
+
manifest_path = tmp_path / "capture.json"
|
| 18 |
+
manifest = import_colmap(cameras, images, tmp_path, {"2"})
|
| 19 |
+
manifest_path.write_text(json.dumps(manifest), encoding="utf-8")
|
| 20 |
+
valid, errors = validate_capture_manifest(manifest_path, check_files=True)
|
| 21 |
+
assert valid is True, errors
|
| 22 |
+
assert manifest["views"][1]["split"] == "held_out"
|
| 23 |
+
assert len(manifest["views"][0]["sha256"]) == 64
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_import_colmap_rejects_unknown_camera_model(tmp_path):
|
| 27 |
+
cameras = tmp_path / "cameras.txt"
|
| 28 |
+
cameras.write_text("1 UNKNOWN 10 10 1 2 3\n", encoding="utf-8")
|
| 29 |
+
images = tmp_path / "images.txt"
|
| 30 |
+
images.write_text("1 1 0 0 0 0 0 0 1 image.png\n", encoding="utf-8")
|
| 31 |
+
try:
|
| 32 |
+
import_colmap(cameras, images, tmp_path)
|
| 33 |
+
except ValueError as exc:
|
| 34 |
+
assert "unsupported COLMAP camera model" in str(exc)
|
| 35 |
+
else:
|
| 36 |
+
raise AssertionError("unknown camera model should fail")
|