feat: ignore boulder.json and update extrinsics visualizer

This commit is contained in:
2026-02-07 15:35:48 +00:00
parent a8d375191a
commit 0d3e9e67ad
7 changed files with 102 additions and 83 deletions
+53 -40
View File
@@ -1,59 +1,72 @@
import numpy as np
import pyzed.sl as sl
from unittest.mock import MagicMock
from typing import Any, cast, TYPE_CHECKING
from aruco.svo_sync import SVOReader
if TYPE_CHECKING:
from _pytest.monkeypatch import MonkeyPatch
def test_retrieve_depth_unit_guard():
class FakeMat:
def __init__(self) -> None:
self.data: np.ndarray = np.array([])
def get_data(self) -> np.ndarray:
return self.data
class FakeInitParameters:
coordinate_units: sl.UNIT
def __init__(self, units: sl.UNIT) -> None:
self.coordinate_units = units
class FakeCamera:
init_params: FakeInitParameters
def __init__(self, units: sl.UNIT) -> None:
self.init_params = FakeInitParameters(units)
def get_init_parameters(self) -> FakeInitParameters:
return self.init_params
def retrieve_measure(self, _mat: Any, _measure: sl.MEASURE) -> sl.ERROR_CODE:
return sl.ERROR_CODE.SUCCESS
def test_retrieve_depth_unit_guard(monkeypatch: "MonkeyPatch") -> None:
# Setup SVOReader with depth enabled
reader = SVOReader([], depth_mode=sl.DEPTH_MODE.ULTRA)
# Mock Camera
mock_cam = MagicMock(spec=sl.Camera)
# Mock depth data (e.g., 2.0 meters)
depth_data = np.full((100, 100), 2.0, dtype=np.float32)
mock_mat = MagicMock(spec=sl.Mat)
mock_mat.get_data.return_value = depth_data
# Mock retrieve_measure to "fill" the mat
mock_cam.retrieve_measure.return_value = sl.ERROR_CODE.SUCCESS
def fake_mat_factory() -> FakeMat:
m = FakeMat()
m.data = depth_data
return m
monkeypatch.setattr("aruco.svo_sync.sl.Mat", fake_mat_factory)
# Case 1: Units are METER -> Should NOT divide by 1000
mock_init_params_meter = MagicMock(spec=sl.InitParameters)
mock_init_params_meter.coordinate_units = sl.UNIT.METER
mock_cam.get_init_parameters.return_value = mock_init_params_meter
fake_cam_meter = FakeCamera(sl.UNIT.METER)
cam_meter = cast(sl.Camera, cast(object, fake_cam_meter))
# We need to patch sl.Mat in the test or just rely on the fact that
# _retrieve_depth creates a new sl.Mat() and calls get_data() on it.
# Since we can't easily mock the sl.Mat() call inside the method without patching,
# let's use a slightly different approach: mock the sl.Mat class itself.
depth_meter = reader._retrieve_depth(cam_meter) # pyright: ignore [reportPrivateUsage]
assert depth_meter is not None
assert np.allclose(depth_meter, 2.0)
with MagicMock() as mock_mat_class:
from aruco import svo_sync
# Case 2: Units are MILLIMETER -> Should divide by 1000
fake_cam_mm = FakeCamera(sl.UNIT.MILLIMETER)
cam_mm = cast(sl.Camera, cast(object, fake_cam_mm))
original_mat = svo_sync.sl.Mat
svo_sync.sl.Mat = mock_mat_class
mock_mat_instance = mock_mat_class.return_value
mock_mat_instance.get_data.return_value = depth_data
# Test METER path
depth_meter = reader._retrieve_depth(mock_cam)
assert depth_meter is not None
assert np.allclose(depth_meter, 2.0)
# Case 2: Units are MILLIMETER -> Should divide by 1000
mock_init_params_mm = MagicMock(spec=sl.InitParameters)
mock_init_params_mm.coordinate_units = sl.UNIT.MILLIMETER
mock_cam.get_init_parameters.return_value = mock_init_params_mm
depth_mm = reader._retrieve_depth(mock_cam)
assert depth_mm is not None
assert np.allclose(depth_mm, 0.002)
# Restore original sl.Mat
svo_sync.sl.Mat = original_mat
depth_mm = reader._retrieve_depth(cam_mm) # pyright: ignore [reportPrivateUsage]
assert depth_mm is not None
assert np.allclose(depth_mm, 0.002)
if __name__ == "__main__":
test_retrieve_depth_unit_guard()
import pytest
_ = pytest.main([__file__])