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:
ComposedTransformationSubclass of
pysdic.ComposedTransformationrepresenting 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 itsparametersare 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.parametersor the parameters of each transformation). Create a new camera to use other transformations.Note
The transformations are not copied: modifying the parameters of
camera.intrinsicmodifies 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.
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()andpysdic.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.NoIntrinsicis used (identity).distortion (Optional[
pysdic.Transformation], optional (default:None)) – The distortion transformation of the camera (2D to 2D). If None,pysdic.NoDistortionis 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.NoExtrinsicis 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:
TypeError – If a transformation is not a
pysdic.Transformation.ValueError – If a transformation has wrong input or output dimensions, or if the sensor size is not positive.
Instantiation#
The Camera class can be instantiated in two ways:
From the sensor size and the transformations with the constructor:
Camera(sensor_height, sensor_width, intrinsic=..., distortion=..., extrinsic=...). The missing transformations are replaced bypysdic.NoIntrinsic,pysdic.NoDistortionandpysdic.NoExtrinsic.From a composition
[extrinsic, distortion, intrinsic](e.g. built withpysdic.compose_projection()) using the classmethodfrom_composition().
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).
|
Create a Camera object from a |
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.
[Get] The distortion transformation of the camera (normalized points to distorted points), describing the optical distortion of the lens. |
|
[Get] The extrinsic transformation of the camera (world points to normalized points), describing the position and orientation of the camera in the world. |
|
[Get] The intrinsic transformation of the camera (distorted points to image points), describing the focal lengths and the principal point. |
|
[Get] The height of the camera sensor in pixels (\(y\)-axis). |
|
[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).
|
Project world points to 2D images points using the camera's extrinsic, distortion and intrinsic transformations. |
|
Get the |
|
Get the |
|
Get the camera rays emitted from the camera sensor to the scene in the world coordinate system for each pixel. |
Visualization#
|
Quickly visualize the sensor of the camera (or an image) and the projection of a point cloud or a mesh with |