Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tools/python_tools/cuvslam_tools/common/edex.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@ def write(self, filename: Path):
# Validate the header and body before writing
new_header = EDEXHeader.model_validate(self.header.model_dump())
new_body = EDEXBody.model_validate(self.body.model_dump())
# by_alias is what puts "size" in the file. Without it pydantic writes the field
# name "resolution", which neither the C++ nor the python reader accepts.
data = [
new_header.model_dump(exclude_none=True),
new_body.model_dump(exclude_none=True),
new_header.model_dump(exclude_none=True, by_alias=True),
new_body.model_dump(exclude_none=True, by_alias=True),
]
with open(filename, "w") as f:
json.dump(data, f, indent=2, cls=EDEXEncoder)
Expand Down
15 changes: 15 additions & 0 deletions tools/python_tools/cuvslam_tools/tests/test_edex.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ def test_read_edex(self):
self.assertEqual(edex.header.cameras[0].intrinsics.resolution.shape, (2,))
self.assertEqual(edex.header.cameras[0].transform.shape, (3, 4))

def test_write_edex_uses_size_key(self):
# Round tripping through EDEXMetadata accepts either spelling, so check the raw json:
# the C++ reader and dataset_reader.py only know "size".
edex = EDEXMetadata.read(DATA_DIR / "edex")
with tempfile.NamedTemporaryFile(
mode="w+", delete=True, encoding="utf-8"
) as temp_file:
edex.write(Path(temp_file.name))
with open(temp_file.name) as f:
header = json.load(f)[0]

for camera in header["cameras"]:
self.assertIn("size", camera["intrinsics"])
self.assertNotIn("resolution", camera["intrinsics"])

def test_read_edex_copy_transform(self):
# Read the intrinsics-only EDEX file
edex_intrinsics = EDEXMetadata.read(DATA_DIR / "edex_intrinsics")
Expand Down
Loading