pysdic.PinholeIntrinsic#
PinholeIntrinsic class#
- class PinholeIntrinsic(*args, **kwargs)[source]#
Bases:
TransformationA subclass of
pysdic.Transformationthat represents the OpenCV pinhole intrinsic camera model using the standard intrinsic matrix. To enable the skew parameter of the intrinsic matrix, setuse_skewto 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 == True5
\((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
applyandinvert.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,)ifuse_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)\) ifuse_skew=True.use_skew (bool, optional (default:
False)) – If True, the skew parameter is enabled and the transformation is parameterized by 5 parameters. IfFalse, 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. IfFalse, 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().
|
Class method to create a |
|
Class method to create a |
|
Class method to create a |
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]ifuse_skew=True).
The pysdic.PinholeIntrinsic defines the following attributes:
[Get] whether the focal lengths can be negative in the model. |
|
[Get/Set] the focal length \(f_x\) of the intrinsic transformation. |
|
[Get/Set] the focal length \(f_y\) of the intrinsic transformation. |
|
[Get/Set] the intrinsic matrix \(K\) of the intrinsic transformation. |
|
[Get/Set] the intrinsic vector \(k\) of the intrinsic transformation. |
|
[Get/Set] the principal point \(c_x\) of the intrinsic transformation. |
|
[Get/Set] the principal point \(c_y\) of the intrinsic transformation. |
|
[Get/Set] the skew parameter \(s\) of the intrinsic transformation. |
|
[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: mapsdistorted_points→image_points.invert: mapsimage_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_pointsdp=True: compute ∂image_points / ∂intrinsic_parameters
|
Apply the intrinsic projection from distorted normalized coordinates to image coordinates. |
|
Apply the inverse of the intrinsic projection from image coordinates to distorted normalized coordinates. |