From cd6f4645ce3f0110106d96578d3e0ed8427b90e3 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Mon, 23 Nov 2026 16:24:02 +1000 Subject: [PATCH] fix: raise NotImplementedError for VISJAC_P depthest=True Visjac_p stored depthest and never used it, so depthest=True silently gave the Jacobian for the fixed depth. Depth estimation needs the camera motion, which the block does not have as an input, so it raises instead. Co-Authored-By: Claude Sonnet 5.5 --- src/machinevisiontoolbox/blocks/camera.py | 19 ++++++++++++++----- tests/test_blocks.py | 10 ++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/machinevisiontoolbox/blocks/camera.py b/src/machinevisiontoolbox/blocks/camera.py index 3d67c100..f476aff6 100644 --- a/src/machinevisiontoolbox/blocks/camera.py +++ b/src/machinevisiontoolbox/blocks/camera.py @@ -74,22 +74,33 @@ def __init__(self, camera, depth=1, depthest=False, **blockargs): :type camera: Camera subclass, optional :param depth: Point depth :type depth: float or ndarray - :param depthest: Use depth estimation, defaults to True + :param depthest: use depth estimation, not implemented so it must be + False (the default). Give the depth with ``depth``. :type depthest: bool, optional :param blockargs: Additional options for the block, passed as a dictionary :type blockargs: dict :return: a VISJAC_P block :rtype: Visjac_p instance + :raises ValueError: if ``camera`` is None + :raises NotImplementedError: if ``depthest`` is True - If the Jacobian - + Computes the image Jacobian (interaction matrix) of the image plane + points on its input, using the same ``depth`` for every point. + .. versionchanged:: 2.5.0 + ``depthest=True`` raises :class:`NotImplementedError`. It was + accepted but did nothing, so the Jacobian was computed with ``depth``. """ # TODO allow a depth input if camera is None: raise ValueError("camera is not defined") + if depthest: + raise NotImplementedError( + "depth estimation is not implemented by the VISJAC_P block, " + "give the depth with the depth argument" + ) super().__init__(**blockargs) @@ -98,8 +109,6 @@ def __init__(self, camera, depth=1, depthest=False, **blockargs): self.depth = depth def output(self, t, inports, x): - # do depth estimation here - J = self.camera.visjac_p(inports[0], self.depth) return [J] diff --git a/tests/test_blocks.py b/tests/test_blocks.py index 18ed1755..d32ba3d6 100644 --- a/tests/test_blocks.py +++ b/tests/test_blocks.py @@ -71,6 +71,16 @@ def test_default_depth_is_one(self): J = self.cam.visjac_p(self.p, 1) nt.assert_array_almost_equal(Visjac_p(self.cam).test_output(self.p)[0], J) + def test_depth_estimation_is_not_implemented(self): + # depthest=True used to be accepted and ignored + with pytest.raises(NotImplementedError, match="depth argument"): + Visjac_p(self.cam, depthest=True) + + def test_depthest_false_is_accepted(self): + block = Visjac_p(self.cam, 5, depthest=False) + J = self.cam.visjac_p(self.p, 5) + nt.assert_array_almost_equal(block.test_output(self.p)[0], J) + def test_jacobian_has_two_rows_per_point(self): p = self.cam.project_point(mkcube(0.2) + np.array([[0], [0], [2]])) J = Visjac_p(self.cam, 2).test_output(p)[0]