pysdic.Camera#

The pysdic.Camera is a pysdic.ComposedTransformation of an extrinsic, a distortion and an intrinsic transformation, \(T = \text{Intrinsic} \circ \text{Distortion} \circ \text{Extrinsic}\), associated with the size of its sensor in pixels.

Camera class#

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

Bases: ComposedTransformation

Subclass of pysdic.ComposedTransformation representing a camera model.

A camera is a structure with :

  • a sensor size (height and width), fixed at the creation of the camera.

  • an extrinsic transformation (world points to normalized points), from 3D world points or from 2D world points for planar problems (the input dimension \(E\) of the camera, camera.input_dim).

  • a distortion transformation (normalized points to distorted points).

  • an intrinsic transformation (distorted points to image points).

The camera is the composition \(T = \text{Intrinsic} \circ \text{Distortion} \circ \text{Extrinsic}\) (see pysdic.compose_projection()), so its parameters are the concatenation of the parameters of the extrinsic, distortion and intrinsic transformations (in this order).

Important

The sensor size and the three transformations cannot be changed after the creation of the camera. Only the parameters of the transformations can be modified (with camera.parameters or the parameters of each transformation). Create a new camera to use other transformations.

Note

The transformations are not copied: modifying the parameters of camera.intrinsic modifies the parameters of the camera, and conversely.

As described in the computer vision literature, the height of the image is along the y-axis and the width of the image is along the x-axis. The following coordinate systems are used in the camera model:

  • world_points: The \(E\)-D points \(\vec{X}_w\) with shape (…,E) expressed in the world coordinate system \((\vec{E}_x, \vec{E}_y, \vec{E}_z)\) (\(E = 3\), or \(E = 2\) for planar problems).

  • normalized_points: The 2-D points \(\vec{x}_n\) with shape (…,2) expressed in the normalized camera coordinate system \((\vec{I}, \vec{J})\) with a unit distance along the optical axis \((\vec{K})\).

  • distorted_points: The distorted 2-D points \(\vec{x}_d\) with shape (…,2) expressed in the normalized camera coordinate system \((\vec{I}, \vec{J})\) with a unit distance along the optical axis \((\vec{K})\).

  • image_points: The 2-D points \(\vec{x}_i\) with shape (…,2) expressed in the image coordinate system \((\vec{e}_x, \vec{e}_y)\) in the sensor plane.

  • pixel_points: The 2-D points \(\vec{x}_p\) with shape (…,2) expressed in the pixel coordinate system \((u, v)\) in the matrix of pixels.

../../_images/cv_definition.png

Definition of quantities in the package.#

To convert the image points to the pixel points, a simple swap of the coordinates is performed with pysdic.Image.image_points_to_pixel_points() and pysdic.Image.pixel_points_to_image_points().

Parameters:
  • sensor_height (Integral) – The height of the camera sensor in pixels (\(y\)-axis), a positive integer.

  • sensor_width (Integral) – The width of the camera sensor in pixels (\(x\)-axis), a positive integer.

  • intrinsic (Optional[pysdic.Transformation], optional (default: None)) – The intrinsic transformation of the camera (2D to 2D). If None, pysdic.NoIntrinsic is used (identity).

  • distortion (Optional[pysdic.Transformation], optional (default: None)) – The distortion transformation of the camera (2D to 2D). If None, pysdic.NoDistortion is used (identity).

  • extrinsic (Optional[pysdic.Transformation], optional (default: None)) – The extrinsic transformation of the camera (3D or 2D world points to 2D). If None, pysdic.NoExtrinsic is used (3D world points).

  • parameters (Optional[ArrayLike], optional (default: None)) – A 1D array of shape \((N_e + N_d + N_i,)\) to set the parameters of the three transformations. If None, the current parameters of the transformations are kept.

Raises:

Instantiation#

The Camera class can be instantiated in two ways:

Important

The sensor size and the three transformations cannot be changed after the creation of the camera. Only their parameters can be modified, with camera.parameters or the parameters of each transformation (they are shared, not copied).

Camera.from_composition(composition, ...)

Create a Camera object from a pysdic.ComposedTransformation of three transformations [extrinsic, distortion, intrinsic] (for example built with pysdic.compose_projection()).

Implemented methods and attributes#

The following sections provide an overview of the attributes and methods defined in the pysdic.Camera class.

Attributes#

The parameters of the camera are inherited from pysdic.ComposedTransformation:

  • parameters: the concatenation [extrinsic, distortion, intrinsic] of the parameters of the three transformations.

Camera.distortion

[Get] The distortion transformation of the camera (normalized points to distorted points), describing the optical distortion of the lens.

Camera.extrinsic

[Get] The extrinsic transformation of the camera (world points to normalized points), describing the position and orientation of the camera in the world.

Camera.intrinsic

[Get] The intrinsic transformation of the camera (distorted points to image points), describing the focal lengths and the principal point.

Camera.sensor_height

[Get] The height of the camera sensor in pixels (\(y\)-axis).

Camera.sensor_width

[Get] The width of the camera sensor in pixels (\(x\)-axis).

Projection and rays#

The apply method of pysdic.Transformation maps the world points to the image points. The following methods give a more convenient access to the projection, the Jacobians of each transformation, and the normalized points and rays of the pixels (cached).

Camera.project(world_points, *[, dx, ...])

Project world points to 2D images points using the camera's extrinsic, distortion and intrinsic transformations.

Camera.get_camera_pixel_points([mask])

Get the pixel_points \((u, v)\) of the camera for each pixel, in row-major order.

Camera.get_camera_normalized_points([mask, ...])

Get the normalized_points of the pixels of the camera, by inverting the intrinsic and distortion transformations (see pysdic.undistort_points()).

Camera.get_camera_rays([mask, distortion_kwargs])

Get the camera rays emitted from the camera sensor to the scene in the world coordinate system for each pixel.

Visualization#

Camera.quick_visualize([geometry, image, ...])

Quickly visualize the sensor of the camera (or an image) and the projection of a point cloud or a mesh with pysdic.ImagePlotter.