|
|
import json |
|
|
from pathlib import Path |
|
|
import numpy as np |
|
|
|
|
|
from ylff.utils.capture_bundle import CaptureBundle |
|
|
|
|
|
|
|
|
def test_capture_bundle_load_and_intrinsics(tmp_path: Path): |
|
|
|
|
|
(tmp_path / "devices" / "iphone_a").mkdir(parents=True) |
|
|
(tmp_path / "calibration").mkdir(parents=True) |
|
|
|
|
|
|
|
|
(tmp_path / "devices" / "iphone_a" / "video.mov").write_bytes(b"") |
|
|
(tmp_path / "devices" / "iphone_a" / "intrinsics.json").write_text( |
|
|
json.dumps({"fx": 1000.0, "fy": 1000.0, "cx": 512.0, "cy": 384.0}) |
|
|
) |
|
|
(tmp_path / "devices" / "iphone_a" / "timestamps.json").write_text(json.dumps({"t": []})) |
|
|
|
|
|
manifest = { |
|
|
"schema_version": "1.0", |
|
|
"capture_id": "cap_001", |
|
|
"devices": [ |
|
|
{ |
|
|
"device_id": "iphone_a", |
|
|
"device_type": "iphone", |
|
|
"label": "iphone_a", |
|
|
"video_path": "devices/iphone_a/video.mov", |
|
|
"intrinsics_path": "devices/iphone_a/intrinsics.json", |
|
|
"timestamps_path": "devices/iphone_a/timestamps.json", |
|
|
} |
|
|
], |
|
|
} |
|
|
(tmp_path / "manifest.json").write_text(json.dumps(manifest)) |
|
|
|
|
|
bundle = CaptureBundle.load(tmp_path) |
|
|
assert bundle.manifest.capture_id == "cap_001" |
|
|
assert bundle.list_devices() == ["iphone_a"] |
|
|
|
|
|
K = bundle.load_intrinsics_matrix("iphone_a") |
|
|
assert K.shape == (3, 3) |
|
|
assert np.isclose(K[0, 0], 1000.0) |
|
|
assert np.isclose(K[1, 2], 384.0) |
|
|
|