pysdic.PlanarHomographicExtrinsic#

PlanarHomographicExtrinsic class#

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

Bases: Transformation

Subclass of pysdic.Transformation implementing a planar homography (projective transformation of the plane).

This class represents an extrinsic transformation in 2D, used to run the camera algorithms on planar problems. It applies a projective transformation to transform 2D world points into 2D normalized points:

world_points → normalized_points → distorted_points → image_points

Given a world point \(\vec{x}_w = (x_w, y_w)\), the corresponding point \(\vec{x}_n = (x_n, y_n)\) in the normalized coordinate system is obtained using homogeneous coordinates:

\[\begin{split}\begin{bmatrix} u \\ v \\ w \end{bmatrix} = H \begin{bmatrix} x_w \\ y_w \\ 1 \end{bmatrix}\end{split}\]

followed by the projective normalization:

\[x_n = \frac{u}{w}, \qquad y_n = \frac{v}{w}\]

The homography matrix is parameterized with 8 parameters by fixing its bottom-right element to one:

\[\begin{split}H = \begin{bmatrix} h_{00} & h_{01} & h_{02} \\ h_{10} & h_{11} & h_{12} \\ h_{20} & h_{21} & 1 \end{bmatrix}\end{split}\]

The homography matrix must be invertible. The inverse transformation is the homography of matrix \(H^{-1}\), so the transformation is both left and right invertible, and all the Jacobians are available for apply and invert.

See also

Note

A homography is defined only up to an arbitrary non-zero scale. The matrix is always normalized so that H[2, 2] = 1, which excludes the homographies with a zero bottom-right element.

Note

The transformation is only defined for points for which the projective denominator \(w\) is non-zero (points not sent to infinity). A ValueError is raised otherwise.

Note

The class can be instantiated in three ways:

  • providing the parameters directly as a numpy array of shape (8,).

  • using the from_hmat() class method to initialize the transformation from a homography matrix (normalized so that H[2, 2] = 1).

  • using the from_eye() class method to initialize the identity transformation.

Parameters:

parameters (Optional[ArrayLike], optional (default: None)) – The homography parameters as a 1D array of shape (8,). The parameters are ordered as \((h_{00}, h_{01}, h_{02}, h_{10}, h_{11}, h_{12}, h_{20}, h_{21})\).

Examples

A homography combining a scaling, a translation and a small perspective effect:

extrinsic = PlanarHomographicExtrinsic.from_hmat(
    [[2.0, 0.0, 1.0],
     [0.0, 2.0, 0.0],
     [0.1, 0.0, 1.0]]
)

extrinsic.apply([[1.0, 1.0]]).x     # array([[2.72727273, 1.81818182]])
extrinsic.invert([[2.72727273, 1.81818182]]).x   # array([[1., 1.]])

Instantiation#

The PlanarHomographicExtrinsic class can be instantiated in three ways:

  • From a parameter vector of shape (8,) passed to the constructor.

  • From a 3×3 homography matrix using the classmethod from_hmat().

  • As the identity homography using the classmethod from_eye().

PlanarHomographicExtrinsic.from_eye()

Create a pysdic.PlanarHomographicExtrinsic representing the identity transformation (\(H = I_3\)).

PlanarHomographicExtrinsic.from_hmat(hmat)

Create a pysdic.PlanarHomographicExtrinsic from a 3x3 homography matrix.

Implemented methods and attributes#

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

Attributes#

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

  • parameters: returns a vector of extrinsic parameters [h00, h01, h02, h10, h11, h12, h20, h21].

The pysdic.PlanarHomographicExtrinsic defines the following attributes:

PlanarHomographicExtrinsic.h00

[Get/Set] the coefficient \(h_{00}\) of the homography matrix (component H[0, 0]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h01

[Get/Set] the coefficient \(h_{01}\) of the homography matrix (component H[0, 1]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h02

[Get/Set] the coefficient \(h_{02}\) of the homography matrix (component H[0, 2]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h10

[Get/Set] the coefficient \(h_{10}\) of the homography matrix (component H[1, 0]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h11

[Get/Set] the coefficient \(h_{11}\) of the homography matrix (component H[1, 1]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h12

[Get/Set] the coefficient \(h_{12}\) of the homography matrix (component H[1, 2]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h20

[Get/Set] the coefficient \(h_{20}\) of the homography matrix (component H[2, 0]), or None if the parameters are not set.

PlanarHomographicExtrinsic.h21

[Get/Set] the coefficient \(h_{21}\) of the homography matrix (component H[2, 1]), or None if the parameters are not set.

PlanarHomographicExtrinsic.homography_matrix

[Get/Set] the 3x3 homogeneous homography matrix \(H\).

Performing Projections#

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

  • apply: maps world_points (2D) → normalized_points.

  • invert: maps normalized_points → world_points (2D).

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

  • dx=True: compute ∂normalized_points / ∂world_points

  • dp=True: compute ∂normalized_points / ∂extrinsic_parameters

PlanarHomographicExtrinsic._apply(...[, dx, dp])

Compute the transformation from 2D world points to 2D normalized points.

PlanarHomographicExtrinsic._invert(...[, dx, dp])

Compute the inverse transformation from 2D normalized points to 2D world points.