File size: 1,514 Bytes
7a87926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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):
    # Minimal bundle layout
    (tmp_path / "devices" / "iphone_a").mkdir(parents=True)
    (tmp_path / "calibration").mkdir(parents=True)

    # Required referenced files
    (tmp_path / "devices" / "iphone_a" / "video.mov").write_bytes(b"")  # placeholder
    (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)