pysdic.PlanarHomographicExtrinsic#
PlanarHomographicExtrinsic class#
- class PlanarHomographicExtrinsic(*args, **kwargs)[source]#
Bases:
TransformationSubclass of
pysdic.Transformationimplementing 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
applyandinvert.See also
Class
pysdic.PlanarRigidExtrinsicfor the rigid motions of the plane.Class
pysdic.WorldPlanePerspectiveExtrinsicfor the homographies induced by a perspective camera with a 3D pose observing the plane \(Z_w = 0\) (6 parameters \((\vec{r}, T)\) instead of 8 free coefficients).
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
ValueErroris 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 thatH[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().
Create a |
|
Create a |
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:
[Get/Set] the coefficient \(h_{00}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{01}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{02}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{10}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{11}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{12}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{20}\) of the homography matrix (component |
|
[Get/Set] the coefficient \(h_{21}\) of the homography matrix (component |
|
[Get/Set] the 3x3 homogeneous homography matrix \(H\). |
Performing Projections#
Use the apply and invert methods from
pysdic.Transformation to perform extrinsic projections:
apply: mapsworld_points(2D) →normalized_points.invert: mapsnormalized_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_pointsdp=True: compute ∂normalized_points / ∂extrinsic_parameters
|
Compute the transformation from 2D world points to 2D normalized points. |
|
Compute the inverse transformation from 2D normalized points to 2D world points. |