diff --git a/src/presa_mano/perception/depth_align.py b/src/presa_mano/perception/depth_align.py index 7c3fbfd..9f30254 100644 --- a/src/presa_mano/perception/depth_align.py +++ b/src/presa_mano/perception/depth_align.py @@ -45,7 +45,6 @@ def align_depth_to_rgb( ) H_rgb, W_rgb = reg.rgb_height, reg.rgb_width - H_ir, W_ir = reg.ir_height, reg.ir_width valid = depth_ir_mm > 0 if not valid.any(): diff --git a/tests/test_depth_align.py b/tests/test_depth_align.py index 095ac27..a7d59a8 100644 --- a/tests/test_depth_align.py +++ b/tests/test_depth_align.py @@ -57,15 +57,15 @@ def test_sparse_pixels_preserved(): def test_z_buffer_keeps_closer_point(): """When two IR pixels collide on the same RGB pixel, the smaller depth wins. - Force a collision with K_ir = 2 × K_rgb (same resolution), so adjacent IR + Force a collision with K_ir = 4 × K_rgb (same resolution), so adjacent IR pixels round to the same RGB pixel.""" W = H = 16 K_rgb = np.array([[60.0, 0.0, W / 2.0], [0.0, 60.0, H / 2.0], [0.0, 0.0, 1.0]], dtype=np.float64) K_ir = K_rgb.copy() - K_ir[0, 0] *= 2.0 # double focal length → two IR pixels collapse to one RGB pixel - K_ir[1, 1] *= 2.0 + K_ir[0, 0] *= 4.0 # 4× focal length → adjacent IR pixels collapse to one RGB pixel + K_ir[1, 1] *= 4.0 reg = CameraRegistration( K_rgb=K_rgb, K_ir=K_ir, R_ir_to_rgb=np.eye(3, dtype=np.float64), @@ -73,16 +73,13 @@ def test_z_buffer_keeps_closer_point(): rgb_width=W, rgb_height=H, ir_width=W, ir_height=H, ) depth_ir = np.zeros((H, W), dtype=np.uint16) - # Two IR pixels (5, 5) and (6, 5) both project to the same RGB pixel near (4, 5) - # (when projected through K_ir with depth 1m and re-projected through K_rgb). - depth_ir[5, 5] = 1500 - depth_ir[5, 6] = 800 + # IR pixels (8, 8) and (8, 9) both project to RGB pixel (8, 8): + # u_rgb = 0.25*(u_ir - 8) + 8 → 8.0 and 8.25 (both round to 8). + depth_ir[8, 8] = 1500 + depth_ir[8, 9] = 800 depth_rgb = align_depth_to_rgb(depth_ir, reg) nonzero = depth_rgb[depth_rgb > 0] - # At least one RGB pixel must receive the closer (800) value; nothing further - # may be ≥ 1500 if a collision actually occurred. If they didn't collide, we - # see exactly two values [800, 1500]; if they did, we see only [800]. - assert nonzero.size in (1, 2) - assert int(nonzero.min()) == 800 - if nonzero.size == 1: - assert int(nonzero[0]) == 800 # collision happened, closer point won + # Exactly one filled pixel; z-buffer kept the closer (800) value. + assert nonzero.size == 1 + assert int(nonzero[0]) == 800 + assert int(depth_rgb[8, 8]) == 800