pycvcam.Cv2Distortion._inverse_transform#

Cv2Distortion._inverse_transform(distorted_points, *, dx=False, dp=False, opencv=False, max_iter=10, eps=1e-08)[source]#

Compute the inverse transformation from the distorted_points to the normalized_points.

Lets consider distorted_points in the camera normalized coordinate system \(\vec{x}_d = (x_d, y_d)\), the corresponding normalized_points in the camera normalized coordinate system are obtained by an iterative algorithm that finds the points \(\vec{x}_n\) such that:

\[\begin{split}\begin{bmatrix} x_n [\text{it }k+1]\\ y_n [\text{it }k+1] \end{bmatrix} = \begin{bmatrix} (x_d - \Delta x [\text{it }k]) / \text{Rad} [\text{it }k] \\ (y_d - \Delta y [\text{it }k]) / \text{Rad}[\text{it }k] \end{bmatrix}\end{split}\]

Where \(\Delta x [\text{it }k]\) and :math:Delta y [text{it }k] are the tangential and prism distortion contributions to the distorted points computed at iteration :math:k. And \(\text{Rad} [\text{it }k]\) is the radial distortion contribution to the distorted points computed at iteration :math:k.

\[\begin{split}\begin{bmatrix} \Delta x \Delta y \end{bmatrix} = \begin{bmatrix} 2 p_1 x_n y_n + p_2 (r^2 + 2x_n^2) + s_1 r^2 + s_2 r^4 \\ 2 p_2 x_n y_n + p_1 (r^2 + 2y_n^2) + s_3 r^2 + s_4 r^4 \end{bmatrix}\end{split}\]
\[\begin{split}\begin{bmatrix} \text{Rad}_x \\ \text{Rad}_y \end{bmatrix} = \begin{bmatrix} \frac{1+k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} \\ \frac{1+k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} \end{bmatrix}\end{split}\]

Warning

This method is not intended to be used directly, but rather through the pycvcam.core.Transform.transform() method. Please ensure, the shape of the input image_points is (n_points, 2) before calling this method.

The jacobians with respect to the distortion parameters and the distorted points are always None, since it is an iterative algorithm.

See also

  • pycvcam.optimize.optimize_input_points() for an other implementation of an iterative algorithm to compute the inverse distortion transformation.

To achieve the inverse distortion transformation using openCV, set the opencv parameter to True.

Parameters:
  • distorted_points (numpy.ndarray) – The distorted points in camera normalized coordinates to be transformed. Shape (n_points, 2).

  • dx (bool, optional) – If True, the jacobian with respect to the distorted points is computed. Default is False

  • dp (bool, optional) – If True, the jacobian with respect to the distortion parameters is computed. Default is False

  • opencv (bool, optional) – If True, the inverse distortion transformation is achieved using the OpenCV function undistortPoints. If False, the inverse distortion transformation is achieved using the internal method. Default is False.

  • max_iter (int, optional) – The maximum number of iterations for the iterative algorithm. Default is 10.

  • eps (float, optional) – The tolerance for the convergence of the iterative algorithm. Default is 1e-8.

Returns:

  • normalized_points (numpy.ndarray) – The normalized points in camera normalized coordinates, which are equal to the x and y components of the image points. Shape (n_points, 2).

  • jacobian_dx (Optional[numpy.ndarray]) – Always None, since the jacobian with respect to the distorted points is not computed by an iterative algorithm.

  • jacobian_dp (Optional[numpy.ndarray]) – Always None, since the jacobian with respect to the distortion parameters is not computed by an iterative algorithm.

Return type:

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