pysdic.PinholeIntrinsic#

PinholeIntrinsic class#

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

Bases: Transformation

A subclass of pysdic.Transformation that represents the OpenCV pinhole intrinsic camera model using the standard intrinsic matrix. To enable the skew parameter of the intrinsic matrix, set use_skew to True when instantiating the class.

This class represents an intrinsic transformation, which is typically the last step in the camera projection pipeline:

world_points → normalized_points → distorted_points → image_points

Let \(\vec{x}_d = (x_d, y_d)\) be a distorted normalized point. The corresponding image point \(\vec{x}_i = (x_i, y_i)\) is obtained using the intrinsic matrix \(K\) in homogeneous coordinates:

\[\begin{split}\begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix} = K \begin{bmatrix} x_d \\ y_d \\ 1 \end{bmatrix}\end{split}\]

where the intrinsic matrix is defined as

\[\begin{split}K = \begin{bmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]

with

  • \(f_x, f_y\) the focal lengths expressed in pixels,

  • \(c_x, c_y\) the principal point coordinates in pixels,

  • \(s\) the skew parameter, only enabled when use_skew=True (otherwise \(s = 0\)).

The transformation is parameterized by 4 to 5 parameters:

Class arguments

\(N\) parameters

parameters

Default configuration

4

\((f_x,f_y,c_x,c_y)\)

use_skew == True

5

\((f_x,f_y,c_x,c_y,s)\)

The transformation is invertible since the focal lengths are non-zero, and all the Jacobians are available for apply and invert.

Note

The class can be instantiated in four ways:

  • providing the parameters directly as a numpy array of shape (4,) containing \((f_x, f_y, c_x, c_y)\), or (5,) if use_skew=True.

  • using the from_matrix() class method to initialize the transformation from an intrinsic matrix.

  • using the from_vector() class method to initialize the transformation from an intrinsic vector.

  • setting the parameters individually using the from_components() class method.

Note

The focal lengths must be non-zero. If allow_negative_focal=False (default), they must also be strictly positive.

Parameters:
  • parameters (Optional[ArrayLike], optional (default: None)) – Intrinsic parameters of shape (4,) ordered as \((f_x, f_y, c_x, c_y)\), or shape (5,) ordered as \((f_x, f_y, c_x, c_y, s)\) if use_skew=True.

  • use_skew (bool, optional (default: False)) – If True, the skew parameter is enabled and the transformation is parameterized by 5 parameters. If False, the skew parameter is disabled and the transformation is parameterized by 4 parameters.

  • allow_negative_focal (bool, optional (default: False)) – If True, focal lengths can be negative. If False, the focal lengths are constrained to remain strictly positive.

Examples

Create an intrinsic transformation and project a distorted normalized point:

intrinsic = PinholeIntrinsic.from_components(fx=1000.0, fy=1000.0, cx=320.0, cy=240.0)

intrinsic.apply([[0.1, -0.2]]).x      # array([[420., 40.]])
intrinsic.invert([[420.0, 40.0]]).x   # array([[ 0.1, -0.2]])
intrinsic.K                           # 3x3 intrinsic matrix

Instantiation#

The PinholeIntrinsic class can be instantiated in three ways:

  • From a 3×3 intrinsic matrix using the classmethod from_matrix().

  • From a parameter vector using the classmethod from_vector().

  • From individual parameters using the classmethod from_components().

PinholeIntrinsic.from_matrix(matrix, **kwargs)

Class method to create a pysdic.PinholeIntrinsic object from an intrinsic matrix \(K\).

PinholeIntrinsic.from_vector(vector, **kwargs)

Class method to create a pysdic.PinholeIntrinsic object from an intrinsic vector \(k\).

PinholeIntrinsic.from_components(fx, fy, cx, cy)

Class method to create a pysdic.PinholeIntrinsic object from the individual components of the intrinsic parameters.

Implemented methods and attributes#

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

Attributes#

The intrinsic parameters can be accessed via the base class pysdic.Transformation:

  • parameters: returns a vector of intrinsic parameters [f_x, f_y, c_x, c_y] (or [f_x, f_y, c_x, c_y, s] if use_skew=True).

The pysdic.PinholeIntrinsic defines the following attributes:

PinholeIntrinsic.allow_negative_focal

[Get] whether the focal lengths can be negative in the model.

PinholeIntrinsic.focal_length_x

[Get/Set] the focal length \(f_x\) of the intrinsic transformation.

PinholeIntrinsic.focal_length_y

[Get/Set] the focal length \(f_y\) of the intrinsic transformation.

PinholeIntrinsic.intrinsic_matrix

[Get/Set] the intrinsic matrix \(K\) of the intrinsic transformation.

PinholeIntrinsic.intrinsic_vector

[Get/Set] the intrinsic vector \(k\) of the intrinsic transformation.

PinholeIntrinsic.principal_point_x

[Get/Set] the principal point \(c_x\) of the intrinsic transformation.

PinholeIntrinsic.principal_point_y

[Get/Set] the principal point \(c_y\) of the intrinsic transformation.

PinholeIntrinsic.skew

[Get/Set] the skew parameter \(s\) of the intrinsic transformation.

PinholeIntrinsic.use_skew

[Get] whether the skew parameter is enabled in the intrinsic transformation.

Performing Projections#

Use the apply and invert methods from pysdic.Transformation to perform intrinsic projections:

  • apply: maps distorted_points → image_points.

  • invert: maps image_points → distorted_points.

Jacobians with respect to the input points and intrinsic parameters can be computed by enabling the dx and dp flags:

  • dx=True: compute ∂image_points / ∂distorted_points

  • dp=True: compute ∂image_points / ∂intrinsic_parameters

PinholeIntrinsic._apply(distorted_points, *)

Apply the intrinsic projection from distorted normalized coordinates to image coordinates.

PinholeIntrinsic._invert(image_points, *[, ...])

Apply the inverse of the intrinsic projection from image coordinates to distorted normalized coordinates.