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
19 changes: 14 additions & 5 deletions src/machinevisiontoolbox/blocks/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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]

Expand Down
10 changes: 10 additions & 0 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading