CUDA Accelerated GStreamer Camera Undistort - CUDA Accelerated GStreamer Camera Undistort Basics

From RidgeRun Developer Connection
< CUDA Accelerated GStreamer Camera Undistort
Revision as of 13:44, 14 November 2021 by Dsoto (talk | contribs) (Camera representation)
Jump to: navigation, search



  Index Next: Getting Started





Camera representation

The cuda-undistort element uses a camera matrix to represent the intrinsic properties of the camera. These parameters are unique to a camera and can be reused as long as it is the same camera. The matrix is defined as follows:

[math]\displaystyle{ \text{camera matrix}=\begin{bmatrix} f_x & 0 & c_x\\ 0 & f_y & c_y\\ 0 & 0 & 1 \\ \end{bmatrix} }[/math]

Where [math]\displaystyle{ (c_x,c_y) }[/math] represents the optical center, and [math]\displaystyle{ (f_x,f_y) }[/math] constitutes the focal length, both measured in pixels.

Image distortion

Image distortion is a phenomenon that produces deviations from the scene to an image; in other words, not all straight lines in the scene remain straight when the image is captured. This can be useful for some applications; however, most of the time it's an undesired product of using different camera lenses.

There are different types of distortion. The cuda undistort element focuses on two main categories: radial and tangential distortion.

Radial distortion

Image distortion can be random and not follow any pattern; however, most of the times it has radial symmetry. The barrel and pincushion distortion are examples of radial distortion. This type of distortion is used by fisheye lenses to capture a wider field of view.

The following graphic represents an example of barrel distortion.

Undistort radial distortion representation.svg

Tangential distortion

This type of distortion is presented when the camera sensor is misaligned with the scene plane, producing a tilted effect like the one shown below.

Undistort tangential distortion representation.svg

Distortion correction models

There are multiple distortion correction models that tackle different types of distortion. The cuda-undistort element implements the Fisheye and Brown-Conrady models.

Notation

  • Distorted pixel locations: [math]\displaystyle{ (x_d,y_d) }[/math]
  • Undistorted pixel locations: [math]\displaystyle{ (x_n,y_n) }[/math]
These are called normalized image coordinates and are calculated from pixel coordinates by translating to the optical center and dividing by the focal length in pixels. Thus, are dimensionless.
  • Radial distortion coefficients: [math]\displaystyle{ (k_1,k_2,k_3,k_4,k_5,k_6) }[/math]
  • Tangential distortion coefficients: [math]\displaystyle{ (p_1,p_2) }[/math]

Fisheye model

This model is used to correct radial distortion only, it is described by the following equations.

[math]\displaystyle{ x_d = \left(1+k_1r^2+k_2r^4+k_3r^6+k_4r^8\right)x_n, }[/math]

[math]\displaystyle{ y_d = \left(1+k_1r^2+k_2r^4+k_3r^6+k_4r^8\right)y_n }[/math]

[math]\displaystyle{ \text{where}\quad r^2=x_n^2 + y_n^2 }[/math]

The cuda-undistort camera calibration tool will provide you with the [math]\displaystyle{ k_1 }[/math], [math]\displaystyle{ k_2 }[/math], [math]\displaystyle{ k_3 }[/math] and [math]\displaystyle{ k_4 }[/math] parameters.

Brown-Conrady model

This model can correct both radial and tangential distortion, it is described by the following equations.

[math]\displaystyle{ x_d = x_n + \left[p_1(r^2+2x_n^2) + 2p_2x_ny_n\right] + x_n\left[1+k_1r^2+k_2r^4+k_3r^6+k_4r^8 + k_5r^{10} + k_6r^{12}\right], }[/math]

[math]\displaystyle{ y_d = y_n + \left[2p_1x_ny_n+p_2(r^2+2y_n^2)\right] + y_n\left[1+k_1r^2+k_2r^4+k_3r^6+k_4r^8 + k_5r^{10} + k_6r^{12}\right] }[/math]

[math]\displaystyle{ \text{where}\quad r^2=x_n^2 + y_n^2 }[/math]

The cuda-undistort camera calibration tool will provide you with the [math]\displaystyle{ k_1 }[/math], [math]\displaystyle{ k_2 }[/math], [math]\displaystyle{ k_3 }[/math], [math]\displaystyle{ k_4 }[/math], [math]\displaystyle{ k_5 }[/math],[math]\displaystyle{ k_6 }[/math], [math]\displaystyle{ p_1 }[/math] and [math]\displaystyle{ p_2 }[/math] parameters.


  Index Next: Getting Started