pysdic.PerspectiveExtrinsic._invert#

PerspectiveExtrinsic._invert(normalized_points, *, dx=False, dp=False, depth=None)[source]#

Compute the inverse transformation from 2D normalized points to 3D world points at a given depth.

The normalized points are placed at the depth \(Z_c\) in the camera coordinate system and transformed back to world coordinates:

\[\begin{split}\vec{X}_c = Z_c \begin{bmatrix} x_n \\ y_n \\ 1 \end{bmatrix}, \qquad \vec{X}_w = R^T \cdot (\vec{X}_c - T)\end{split}\]

The Jacobian with respect to the normalized points (the depth is fixed) is:

\[\begin{split}\frac{\partial \vec{X}_w}{\partial \vec{x}_n} = Z_c R^T \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{bmatrix}\end{split}\]

The Jacobian with respect to the parameters \((\vec{r}, T)\) is:

\[\frac{\partial \vec{X}_w}{\partial r_k} = \frac{\partial R}{\partial r_k}^T (\vec{X}_c - T), \qquad \frac{\partial \vec{X}_w}{\partial T} = - R^T\]

Note

The depth is an additional argument of invert: extrinsic.invert(points, depth=...). The inverse is a right inverse of apply only for positive depths: the depths \(Z_c \leq 0\) (behind the camera) are rejected.

Parameters:
  • normalized_points (numpy.ndarray) – Input 2D normalized points in camera coordinates. Shape (n_points, 2).

  • dx (bool, optional (default: False)) – If True, compute the Jacobian with respect to normalized points.

  • dp (bool, optional (default: False)) – If True, compute the Jacobian with respect to extrinsic parameters.

  • depth (Optional[ArrayLike], optional (default: None)) – Depth \(Z_c\) of the points in camera coordinates. It can be a scalar or an array with one value per point (with the same batch shape as the points passed to invert). If None, all depths are equal to 1.0. The depths must be strictly positive.

Returns:

  • world_points (numpy.ndarray) – 3D points in world coordinates. Shape (n_points, 3).

  • jacobian_dx (Optional[numpy.ndarray]) – Jacobian of world points with respect to normalized points. Shape (n_points, 3, 2) if dx=True, otherwise None.

  • jacobian_dp (Optional[numpy.ndarray]) – Jacobian of world points with respect to extrinsic parameters. Shape (n_points, 3, 6) if dp=True, otherwise None.

Raises:

ValueError – If at least one depth is not strictly positive (point behind the camera).

Return type:

Tuple[ndarray, ndarray | None, ndarray | None]