fix: implement per-camera ground plane correction
This commit is contained in:
@@ -466,7 +466,7 @@ def test_refine_ground_from_depth_success():
|
||||
# We started with floor at y=-1.0. Target is y=0.0.
|
||||
# So we expect translation of +1.0 in Y.
|
||||
# T_corr should have ty approx 1.0.
|
||||
T_corr = metrics.correction_transform
|
||||
T_corr = metrics.camera_corrections["cam1"]
|
||||
assert abs(T_corr[1, 3] - 1.0) < 0.1 # Allow some slack for RANSAC noise
|
||||
|
||||
# Check new extrinsics
|
||||
@@ -475,3 +475,70 @@ def test_refine_ground_from_depth_success():
|
||||
# New T origin y should be -3 + 1 = -2.
|
||||
T_new = new_extrinsics["cam1"]
|
||||
assert abs(T_new[1, 3] - (-2.0)) < 0.1
|
||||
|
||||
# Verify per-camera corrections
|
||||
assert "cam1" in metrics.camera_corrections
|
||||
assert "cam2" in metrics.camera_corrections
|
||||
assert len(metrics.camera_corrections) == 2
|
||||
|
||||
|
||||
def test_refine_ground_from_depth_partial_success():
|
||||
# 2 cameras, but only 1 finds a plane
|
||||
# Should still succeed if min_valid_cameras=1 (or if we relax it)
|
||||
# But config default is 2.
|
||||
# Let's set min_valid_cameras=1
|
||||
config = GroundPlaneConfig(
|
||||
min_valid_cameras=1,
|
||||
min_inliers=10,
|
||||
target_y=0.0,
|
||||
)
|
||||
|
||||
width, height = 20, 20
|
||||
K = np.eye(3)
|
||||
K[0, 2] = 10
|
||||
K[1, 2] = 10
|
||||
K[0, 0] = 20
|
||||
K[1, 1] = 20
|
||||
|
||||
# Cam 1: Valid plane (same as success test)
|
||||
Rx_neg90 = np.array([[1, 0, 0], [0, 0, 1], [0, -1, 0]])
|
||||
t = np.array([0, -3, 0])
|
||||
T_world_cam = np.eye(4)
|
||||
T_world_cam[:3, :3] = Rx_neg90
|
||||
T_world_cam[:3, 3] = t
|
||||
depth_map_valid = np.full((height, width), 2.0, dtype=np.float32)
|
||||
|
||||
# Need to ensure we have enough points for RANSAC
|
||||
config.stride = 1
|
||||
|
||||
# Cam 2: Invalid depth (zeros)
|
||||
depth_map_invalid = np.zeros((height, width), dtype=np.float32)
|
||||
|
||||
camera_data = {
|
||||
"cam1": {"depth": depth_map_valid, "K": K},
|
||||
"cam2": {"depth": depth_map_invalid, "K": K},
|
||||
}
|
||||
extrinsics = {
|
||||
"cam1": T_world_cam,
|
||||
"cam2": T_world_cam,
|
||||
}
|
||||
|
||||
new_extrinsics, metrics = refine_ground_from_depth(camera_data, extrinsics, config)
|
||||
|
||||
assert metrics.success
|
||||
assert metrics.num_cameras_valid == 1
|
||||
assert metrics.correction_applied
|
||||
|
||||
# Cam 1 should be corrected
|
||||
assert "cam1" in metrics.camera_corrections
|
||||
assert "cam1" not in metrics.skipped_cameras
|
||||
|
||||
# Cam 2 should be skipped
|
||||
assert "cam2" not in metrics.camera_corrections
|
||||
assert "cam2" in metrics.skipped_cameras
|
||||
|
||||
# Cam 2 extrinsics should be unchanged
|
||||
np.testing.assert_array_equal(new_extrinsics["cam2"], extrinsics["cam2"])
|
||||
|
||||
# Cam 1 extrinsics should be changed
|
||||
assert not np.array_equal(new_extrinsics["cam1"], extrinsics["cam1"])
|
||||
|
||||
Reference in New Issue
Block a user