pycvcam.Cv2Distortion._transform#
- Cv2Distortion._transform(normalized_points, *, dx=False, dp=False, opencv=False)[source]#
Compute the transformation from the
normalized_pointsto thedistorted_points.Lets consider
normalized_pointsin the camera normalized coordinate system \(\vec{x}_n = (x_n, y_n)\), the correspondingdistorted_pointsin the camera normalized coordinate system are given \(\vec{x}_d\) can be obtained by :\[\vec{x}_d = \text{distort}(\vec{x}_n, \lambda_1, \lambda_2, \lambda_3, \ldots)\]The model of OpenCV is the following one:
\[\begin{split}\begin{bmatrix} x_d \\ y_d \end{bmatrix} = \begin{bmatrix} x_n \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} + 2p_1 x_n y_n + p_2 (r^2 + 2x_n^2) + s_1 r^2 + s_2 r^4 \\ y_n \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} + p_1 (r^2 + 2y_n^2) + 2p_2 x_n y_n + s_3 r^2 + s_4 r^4 \end{bmatrix}\end{split}\]where \(r^2 = x_n^2 + y_n^2\) and \(k_i\) are the radial distortion coefficients, \(p_i\) are the tangential distortion coefficients and \(s_i\) are the thin prism distortion coefficients.
Then a perspective transformation is applied using \(\tau_x\) and \(\tau_y\) to obtain the final distorted points.
\[\begin{split}\begin{bmatrix} x_d \\ y_d \\ 1 \end{bmatrix} = \begin{bmatrix} R_{33}(\tau) & 0 & -R_{13}(\tau) \\ 0 & R_{33}(\tau) & -R_{23}(\tau) \\ 0 & 0 & 1 \end{bmatrix} R(\tau) \begin{bmatrix} x_d \\ y_d \\ 1 \end{bmatrix}\end{split}\]where :
\[\begin{split}R(\tau) = \begin{bmatrix} cos(\tau_y) & sin(\tau_x)sin(\tau_y) & -cos(\tau_x)sin(\tau_y) \\ 0 & cos(\tau_x) & sin(\tau_x) \\ sin(\tau_y) & -sin(\tau_x)cos(\tau_y) & cos(\tau_x)cos(\tau_y) \end{bmatrix}\end{split}\]The jacobians with respect to the distortion parameters is an array with shape (n_points, 2, n_params), where the last dimension represents the parameters in the order of the class attributes (k1, k2, k3, p1, p2, k4, k5, k6, s1, s2, s3, s4, tau_x, tau_y). The jacobian with respect to the normalized points is an array with shape (n_points, 2, 2).
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 inputnormalized_pointsis (n_points, 2) before calling this method.To achieve the distortion transformation using openCV, set the
opencvparameter to True. (jacobian_dxwill not be computed in this case).- Parameters:
normalized_points (numpy.ndarray) – The normalized points in camera normalized coordinates to be transformed. Shape (n_points, 2).
dx (bool, optional) – If True, the jacobian with respect to the normalized 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 distortion transformation is achieved using the OpenCV function
projectPoints. If False, the distortion transformation is achieved using the internal method. Default is False.
- Returns:
distorted_points (numpy.ndarray) – The distorted points in camera normalized coordinates. Shape (n_points, 2).
jacobian_dx (Optional[numpy.ndarray]) – The jacobian of the distorted points with respect to the normalized points. Shape (n_points, 2, 2) if dx is True, otherwise None.
jacobian_dp (Optional[numpy.ndarray]) – The jacobian of the distorted points with respect to the distortion parameters. Shape (n_points, 2, n_params) if dp is True, otherwise None.
- Return type: