pycvcam.Cv2Distortion._compute_tilt_matrix#

Cv2Distortion._compute_tilt_matrix(dp=True, inv=True)[source]#

Compute the tilt matrix for the perspective transformation for N = 14 (only).

The tilt matrix is computed using the following equation:

\[R_{\text{tilt}}{\tau} = R_Z[R_Y R_X] R_Y R_X\]

where \(R_X\) and \(R_Y\) are the rotation matrices along X and Y respectively, and \(R_Z\) is the rotation matrix along Z.

\[\begin{split}R_X = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos(\tau_x) & \sin(\tau_x) \\ 0 & -\sin(\tau_x) & \cos(\tau_x) \end{pmatrix}\end{split}\]
\[\begin{split}R_Y = \begin{pmatrix} \cos(\tau_y) & 0 & -\sin(\tau_y) \\ 0 & 1 & 0 \\ \sin(\tau_y) & 0 & \cos(\tau_y) \end{pmatrix}\end{split}\]

and we note that the rotation matrix along Z is given by:

\[\begin{split}R_z[R] = \begin{pmatrix} R_{33} & 0 & -R_{13} \\ 0 & R_{33} & -R_{23} \\ 0 & 0 & 1 \end{pmatrix}\end{split}\]

The derivatives of the tilt matrix with respect to \(\tau_x\) and \(\tau_y\) are also computed. The derivatives are computed using the following equations:

\[\frac{\partial R_{\text{tilt}}}{\partial \tau_x} = R_Z [R_Y \frac{\partial R_X}{\partial \tau_x}, 0] R_Y R_X + R_Z [R_Y R_X, 1] R_Y \frac{\partial R_X}{\partial \tau_x}\]
\[\frac{\partial R_{\text{tilt}}}{\partial \tau_y} = R_Z [\frac{\partial R_Y}{\partial \tau_y} R_X, 0] R_Y R_X + R_Z [R_Y R_X, 1] \frac{\partial R_Y}{\partial \tau_y} R_X\]

Finnally, the inverse of the tilt matrix is computed using the following equation:

\[R_{\text{tilt}}^{-1} = (Ry Rx).T @ invRz[Ry Rx]\]

Where \(invRz\) is the inverse of the rotation matrix along Z given by:

\[\begin{split}(R_z[R])^{-1} = \begin{pmatrix} 1/R_{33} & 0 & R_{13}/R_{33} \\ 0 & 1/R_{33} & R_{23}/R_{33} \\ 0 & 0 & 1 \end{pmatrix}\end{split}\]

Note

If the model is not set to 14 parameters, the method returns a identity matrix and the derivatives are set to zero.

Parameters:
  • dp (bool, optional) – If True, the derivatives of the tilt matrix are computed. The default is True. If False, the derivatives are set to None.

  • inv (bool, optional) – If True, the inverse of the tilt matrix is computed. The default is True. If False, the inverse of the tilt matrix is set to None.

Returns:

  • numpy.ndarray – The tilt matrix.

  • numpy.ndarray – The derivative of the tilt matrix with respect to \(\tau_x\) if dp is True, else None.

  • numpy.ndarray – The derivative of the tilt matrix with respect to \(\tau_y\) if dp is True, else None.

  • numpy.ndarray – The inverse of the tilt matrix if inv is True, else None.

Return type:

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