Computer Vision Cameras Models (Extrinsic, Distortion, Intrinsic)#

A camera projection model is a mathematical representation of how a camera captures and projects a 3D scene onto a 2D image plane. The following sections describe the camera projection models implemented in the package, their nomenclature, parameters, and the processes available to project points, distort images or compute rays.

Important

All the camera operations in pysdic to process the transformation from the world points to the image points are based on the pysdic.Transformation interface (see Morphisms). Any custom transformation implementing this interface can be used as an extrinsic, a distortion or an intrinsic.

Definition of Notations#

A computer vision camera is modeled by three main components:

  1. Extrinsic: The transformation from the world coordinate system to the normalized camera coordinate system (world points to normalized points)

  2. Distortion: The transformation from the normalized camera coordinate system to the distorted camera coordinate system (normalized points to distorted points)

  3. Intrinsic: The transformation from the distorted camera coordinate system to the image coordinate system (distorted points to image points)

world_points → normalized_points → distorted_points → image_points

The complete projection is the composition \(T = \text{Intrinsic} \circ \text{Distortion} \circ \text{Extrinsic}\) (see pysdic.compose_projection()).

As described in the figure below, the package pysdic uses the following notation:

  • world_points: The 3-D points \(\vec{X}_w\) with shape (…,3) expressed in the world coordinate system \((\vec{E}_x, \vec{E}_y, \vec{E}_z)\), or the 2-D points \(\vec{x}_w\) with shape (…,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 ``pysdic``.

The coordinate systems are defined as follows:

  • world coordinate system: The 3-D coordinate system \((\vec{E}_x, \vec{E}_y, \vec{E}_z)\) in which the 3-D points are expressed.

  • normalized camera coordinate system: The 2-D coordinate system \((\vec{I}, \vec{J})\) extracted from the 3-D camera system \((\vec{I}, \vec{J}, \vec{K})\) by applying the extrinsic transformation. This 2-D plane is orthogonal to the optical axis \(\vec{K}\).

  • image coordinate system: The 2-D coordinate system \((\vec{e}_x, \vec{e}_y)\) in the image plane with the origin at the top-left corner of the image and the axes defined by the sensor plane (width and height).

  • pixel coordinate system: The 2-D coordinate system \((u, v)\) in the matrix of pixels with the origin at the top-left corner of the image and the axes defined by the pixel grid (width and height).

Note

To convert the pixel points to the image points (swapping from pixel coordinates to image coordinates), a simple switch of coordinate system can be performed:

pixel_points = numpy.indices((img_height, img_width)).reshape(2, -1).T  # Axis [H, W -> Y, X]
image_points = pixel_points[:, [1, 0]]  # Swap to [X, Y] format

Morphisms (Transformations and Parametrizations)#

The extrinsic, distortion and intrinsic models are subclasses of pysdic.Transformation. The parameters of a transformation can be re-expressed with a pysdic.Parametrization (for example to optimize only some of them), and several transformations can be composed together.

Morphisms

This section describes the common interface of the transformations and parametrizations (apply, invert, encode, decode, Jacobians, compositions and reparametrizations).

Implemented transformations and parametrizations#

The package pysdic provides a set of implemented transformations that can be used to process the transformation from the world points to the image points, and a set of implemented parametrizations.

Implemented Extrinsic

The implemented Extrinsic models from the world points (3D or 2D) to the normalized points, and the camera rays.

Implemented Distortion

The implemented Distortion models from the normalized points to the distorted points.

Implemented Intrinsic

The implemented Intrinsic models from the distorted points to the image points.

Implemented Parametrizations

The implemented Parametrization models to change the parametric representation of a transformation.

Projection of points#

Project the world points to the image points through the extrinsic, distortion and intrinsic transformations, with optional Jacobians with respect to the points and to the parameters of each step.

Distortion of points and images#

Distort or undistort the image points or whole images with the intrinsic and distortion transformations (and an optional rectification \(R\) and projection \(P\) for the points).

Rays and triangulation#

Compute the rays of a camera through the image points and triangulate the points seen by several cameras (see also the class pysdic.Rays in Implemented Extrinsic).

  • compute_rays: Compute the rays in the world coordinate system through the image points.

  • intersect_rays: Compute the point closest to several rays in the least squares sense.

Optical flow operations#

The package includes functions to compute the optical flow between two images based on the OpenCV DIS (Dense Inverse Search) algorithm.

See the section Usage for more details and examples on how to use these processes.

Optimisation processes#

The package provides optimisation processes based on the Gauss-Newton solver pysolvegn to estimate the parameters or the input points of the transformations. The transformations are combined in chains: a chain is a sequence of indices of transformations applied in this order (for example (0, 2, 3) is \(T_3 \circ T_2 \circ T_0\)), and a transformation can be shared by several chains (for example the intrinsic and distortion of a camera observing a target in several positions).

Each process comes in two versions:

  • build_*_term: build a pysolvegn term and the initial vector p0, to combine several terms (different losses or weights) or to use the advanced options of pysolvegn.

  • optimize_*: build the term and directly solve the problem.

The terms can be built in mode "rJ" (residuals and Jacobian, with robust losses) or "gH" (gradient and Gauss-Newton Hessian, lower memory).

Optimization of the parameters#

Estimate the parameters \(\vec{p}\) of the transformations such that \(C_c(X_c; \vec{p}) \approx Y_c\) for each chain (for example the calibration of a camera, with pysolvegn.solve).

Optimization of the input points#

Estimate the input points \(X\) such that \(C_c(X) \approx Y_c\) for each chain, the parameters being fixed (for example a numerical inverse of a transformation, or the triangulation of points seen by several cameras). Each point is an independent problem solved with pysolvegn.solve_batch.

Create a Camera Object by Composing Transformations#

The package provides a pysdic.Camera class that is used for SDIC applications. This class is a wrapper around the transformations and processes described above, which allows to create a camera model by composing the extrinsic, distortion, and intrinsic transformations together, and to apply the transformations and processes to points or images.

See also

See the section Imaging Model for more details on how to create a pysdic.Camera and how to use it for SDIC applications.