Camera geometry blocks#

https://raw.githubusercontent.com/petercorke/bdsim/master/figs/BDSimLogo_NoBackgnd@2x.png

These blocks model camera projection functions.

Machine Vision blocks: - have inputs and outputs - are a subclass of FunctionBlock → Block for kinematics and have no states - are a subclass of TransferBlock → Block for dynamics and have states

class Camera(*args: Any, **kwargs: Any)[source][source]#

Bases: FunctionBlock

CAMERA

Camera projection block.

Parameters:
  • camera – camera model, a subclass of CameraBase

  • args – not used

  • blockargs – Additional options for the block, passed as a dictionary

Raises:

ValueError – if camera is None

Returns:

a CAMERA block

Return type:

Camera instance

Camera projection model.

Block ports

input P:

world points as ndarray(3,N)

input ξ:

camera pose as an SE3 object

output p:

image plane points as ndarray(2,N)

__init__(camera: CameraBase | None = None, args: dict[str, Any] = {}, **blockargs: Any) → None[source][source]#
Parameters:
  • camera – camera model, a subclass of CameraBase

  • args – not used

  • blockargs – Additional options for the block, passed as a dictionary

Raises:

ValueError – if camera is None

Returns:

a CAMERA block

Return type:

Camera instance

Camera projection model.

Block ports

input P:

world points as ndarray(3,N)

input ξ:

camera pose as an SE3 object

output p:

image plane points as ndarray(2,N)

class Visjac_p(*args: Any, **kwargs: Any)[source][source]#

Bases: FunctionBlock

VISJAC_P

Interaction-matrix block for image points.

Parameters:
  • camera – camera model

  • depth (float or ndarray(N)) – point depth, a scalar or one value per point

  • depthest – use depth estimation, not implemented so it must be False (the default). Give the depth with depth.

  • blockargs – Additional options for the block, passed as a dictionary

Raises:
Returns:

a VISJAC_P block

Return type:

Visjac_p instance

Computes the image Jacobian (interaction matrix) of the image plane points on its input, using the same depth for every point, see visjac_p.

Block ports

input p:

image plane points as ndarray(2,N)

output J:

image Jacobian as ndarray(2N,6)

Changed in version 2.5.0: depthest=True raises NotImplementedError. It was accepted but did nothing, so the Jacobian was computed with depth.

__init__(camera: CentralCamera, depth: float | ndarray = 1, depthest: bool = False, **blockargs: Any) → None[source][source]#
Parameters:
  • camera – camera model

  • depth (float or ndarray(N)) – point depth, a scalar or one value per point

  • depthest – use depth estimation, not implemented so it must be False (the default). Give the depth with depth.

  • blockargs – Additional options for the block, passed as a dictionary

Raises:
Returns:

a VISJAC_P block

Return type:

Visjac_p instance

Computes the image Jacobian (interaction matrix) of the image plane points on its input, using the same depth for every point, see visjac_p.

Block ports

input p:

image plane points as ndarray(2,N)

output J:

image Jacobian as ndarray(2N,6)

Changed in version 2.5.0: depthest=True raises NotImplementedError. It was accepted but did nothing, so the Jacobian was computed with depth.

class EstPose_p(*args: Any, **kwargs: Any)[source][source]#

Bases: FunctionBlock

ESTPOSE_P

Pose-estimation block for image points.

Parameters:
  • camera – camera model

  • P (ndarray(3,N)) – world point coordinates

  • frame – return pose of points with respect to reference frame which is one of: ‘world’ [default] or ‘camera’

  • method – pose estimation algorithm one of: ‘iterative’ [default], ‘epnp’, ‘p3p’, ‘ap3p’, ‘ippe’, ‘ippe-square’

  • blockargs – Additional options for the block, passed as a dictionary

Returns:

a ESTPOSE_P block

Return type:

EstPose_p instance

Raises:
  • ValueError – if camera is None or frame is not "world" or "camera"

  • RuntimeError – when the diagram is evaluated, if the pose estimation finds no solution for the points. bdsim prints the block, the time and the input, and stops the run with a “Fatal failure” error caused by this one.

Changed in version 2.5.0: frame is now passed to estpose. Previously it was accepted but ignored, so the pose was always given with respect to the world frame.

Changed in version 2.5.0: A pose estimate that fails raises RuntimeError. It used to output None, which the next block received as its input.

__init__(camera: CentralCamera, P: ndarray, frame: str = 'world', method: str = 'iterative', **blockargs: Any) → None[source][source]#
Parameters:
  • camera – camera model

  • P (ndarray(3,N)) – world point coordinates

  • frame – return pose of points with respect to reference frame which is one of: ‘world’ [default] or ‘camera’

  • method – pose estimation algorithm one of: ‘iterative’ [default], ‘epnp’, ‘p3p’, ‘ap3p’, ‘ippe’, ‘ippe-square’

  • blockargs – Additional options for the block, passed as a dictionary

Returns:

a ESTPOSE_P block

Return type:

EstPose_p instance

Raises:
  • ValueError – if camera is None or frame is not "world" or "camera"

  • RuntimeError – when the diagram is evaluated, if the pose estimation finds no solution for the points. bdsim prints the block, the time and the input, and stops the run with a “Fatal failure” error caused by this one.

Changed in version 2.5.0: frame is now passed to estpose. Previously it was accepted but ignored, so the pose was always given with respect to the world frame.

Changed in version 2.5.0: A pose estimate that fails raises RuntimeError. It used to output None, which the next block received as its input.

class ImagePlane(*args: Any, **kwargs: Any)[source][source]#

Bases: GraphicsBlock

IMAGEPLANE

Graphics block that displays points on the image plane.

Create a block that plots image plane coordinates.

Parameters:
  • camera – camera model, which draws the image plane

  • style – style for the points to be plotted, a dict of Matplotlib line properties which is added to the default style, or a format string such as "r*"

  • labels – not used

  • grid – draw a grid, defaults to True. Can be a bool or a tuple of options for grid()

  • retain – keep previous image plane points, defaults to False

  • watch – add the input signal to the watchlist, defaults to False

  • init – function to initialize the graphics, called once with the camera when the simulation starts, defaults to None

  • blockargs – Additional options for the block, passed as a dictionary

Raises:

ValueError – if camera is None or style is not a str or dict

Returns:

An IMAGEPLANE block

Return type:

ImagePlane instance

Create a block that plots points on a camera object’s virtual image plane.

Block ports

input p:

image plane points as ndarray(2,N)

Examples:

IMAGEPLANE(camera)
IMAGEPLANE(camera, style="r*")
IMAGEPLANE(camera, style=dict(marker="s", markersize=9), retain=True)
IMAGEPLANE(camera, grid=False)

Changed in version 2.5.0: Works with the graphics block interface of bdsim 1.5: watch=True no longer fails, only one figure is opened, and nothing is drawn when graphics are turned off.

__init__(camera: CameraBase, style: str | dict[str, Any] | None = None, labels: Any = None, grid: bool | list[Any] | tuple[Any, ...] = True, retain: bool = False, watch: bool = False, init: Callable[[CameraBase], None] | None = None, **blockargs: Any) → None[source][source]#

Create a block that plots image plane coordinates.

Parameters:
  • camera – camera model, which draws the image plane

  • style – style for the points to be plotted, a dict of Matplotlib line properties which is added to the default style, or a format string such as "r*"

  • labels – not used

  • grid – draw a grid, defaults to True. Can be a bool or a tuple of options for grid()

  • retain – keep previous image plane points, defaults to False

  • watch – add the input signal to the watchlist, defaults to False

  • init – function to initialize the graphics, called once with the camera when the simulation starts, defaults to None

  • blockargs – Additional options for the block, passed as a dictionary

Raises:

ValueError – if camera is None or style is not a str or dict

Returns:

An IMAGEPLANE block

Return type:

ImagePlane instance

Create a block that plots points on a camera object’s virtual image plane.

Block ports

input p:

image plane points as ndarray(2,N)

Examples:

IMAGEPLANE(camera)
IMAGEPLANE(camera, style="r*")
IMAGEPLANE(camera, style=dict(marker="s", markersize=9), retain=True)
IMAGEPLANE(camera, grid=False)

Changed in version 2.5.0: Works with the graphics block interface of bdsim 1.5: watch=True no longer fails, only one figure is opened, and nothing is drawn when graphics are turned off.

record(t: float, inports: list[Any]) → None[source][source]#