Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
undistortion.c File Reference

Functions for undistorting camera images. More...

#include "undistortion.h"
#include <math.h>
+ Include dependency graph for undistortion.c:

Go to the source code of this file.

Functions

bool Dhane_distortion (float x_n, float y_n, float *x_nd, float *y_nd, float k)
 Distort normalized image coordinates with the invertible Dhane method. More...
 
bool Dhane_undistortion (float x_nd, float y_nd, float *x_n, float *y_n, float k)
 Undistort distorted normalized image coordinates with the invertible Dhane method. More...
 
void normalized_to_pixels (float x_n_, float y_n_, float *x_p, float *y_p, const float *K)
 Transform normalized coordinates to pixel coordinates. More...
 
void pixels_to_normalized (float x_p, float y_p, float *x_n_, float *y_n_, const float *K)
 Transform pixel coordinates to normalized coordinates. More...
 
bool distorted_pixels_to_normalized_coords (float x_pd, float y_pd, float *x_n, float *y_n, float k, const float *K)
 Transform distorted pixel coordinates to normalized coordinates. More...
 
bool normalized_coords_to_distorted_pixels (float x_n, float y_n, float *x_pd, float *y_pd, float k, const float *K)
 Transform normalized coordinates to distorted pixel coordinates. More...
 

Detailed Description

Functions for undistorting camera images.

The lenses of most cameras distort the image, in the sense that it does not represent a linear projection of points in the world. Specifically, straight lines in the world get curved in the image, as the lens compresses the data more and more towards the edges of the image.

Reading:

  1. https://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html (for normal cameras)
  2. https://docs.opencv.org/trunk/db/d58/group__calib3d__fisheye.html (for fisheye cameras)
  3. Dhane, P., Kutty, K., & Bangadkar, S. (2012). A generic non-linear method for fisheye correction. International Journal of Computer Applications, 51(10). (invertible fisheye model)

Some definitions:

  • x_n, y_n: Normalized coordinates, i.e., with no distortion, with (0,0) the center of the image, and x_n = X / Z
  • x_nd, y_nd: Distorted normalized coordinates, i.e., with (0,0) the center of the image, but x_nd and y_nd are a nonlinear function of X/Z
  • x_n_, y_n_: Normalized coordinates, whether distorted or undistorted.
  • x_p, y_p: Pixel coordinates, with (0,0) the start of the image, and x_pd, y_pd in the range [0,width] and [0,height], respectively.
  • k: distortion parameters
  • K: camera calibration matrix, as a single array in row-major form, so K00, K01, K02, K10, K11, ...

Definition in file undistortion.c.

Function Documentation

bool Dhane_distortion ( float  x_n,
float  y_n,
float *  x_nd,
float *  y_nd,
float  k 
)

Distort normalized image coordinates with the invertible Dhane method.

This can be useful for undistorting an entire image. We assume f, the focal length, to be 1 here. That is why it is missing from the below formula.

Parameters
[in]x_nThe undistorted normalized x coordinate
[in]y_nThe undistorted normalized y coordinate
[in]kThe single parameter of Dhane's model, typically found empirically by checking if straight lines in the world are straight in an undistorted image.
[out]*x_ndThe distorted normalized x coordinate
[out]*y_ndThe distorted normalized y coordinate
Returns
Whether the distortion was successful

Definition at line 57 of file undistortion.c.

Referenced by normalized_coords_to_distorted_pixels().

+ Here is the caller graph for this function:

bool Dhane_undistortion ( float  x_nd,
float  y_nd,
float *  x_n,
float *  y_n,
float  k 
)

Undistort distorted normalized image coordinates with the invertible Dhane method.

We assume f, the focal length, to be 1 here. That is why it is missing from the below formula.

Parameters
[out]*x_nThe undistorted normalized x coordinate
[out]*y_nThe undistorted normalized y coordinate
[in]kThe single parameter of Dhane's model, typically found empirically by checking if straight lines in the world are straight in an undistorted image.
[in]x_ndThe distorted normalized x coordinate
[in]y_ndThe distorted normalized y coordinate
Returns
Whether the distortion was successful

Definition at line 76 of file undistortion.c.

Referenced by distorted_pixels_to_normalized_coords().

+ Here is the caller graph for this function:

bool distorted_pixels_to_normalized_coords ( float  x_pd,
float  y_pd,
float *  x_n,
float *  y_n,
float  k,
const float *  K 
)

Transform distorted pixel coordinates to normalized coordinates.

Parameters
[out]*x_nThe undistorted normalized x coordinate
[out]*y_nThe undistorted normalized y coordinate
[in]kThe single parameter of Dhane's model, typically found empirically by checking if straight lines in the world are straight in an undistorted image.
[in]*KThe camera calibration matrix, as a single array in row-major form, so K00, K01, K02, K10, K11, ...
[in]x_pdThe distorted pixel x coordinate
[in]y_pdThe distorted pixel y coordinate
Returns
Whether the transformation was successful

Definition at line 128 of file undistortion.c.

References Dhane_undistortion(), and pixels_to_normalized().

Referenced by get_world_position_from_image_points(), and predict_flow_vectors().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool normalized_coords_to_distorted_pixels ( float  x_n,
float  y_n,
float *  x_pd,
float *  y_pd,
float  k,
const float *  K 
)

Transform normalized coordinates to distorted pixel coordinates.

Parameters
[in]x_nThe undistorted normalized x coordinate
[in]y_nThe undistorted normalized y coordinate
[in]kThe single parameter of Dhane's model, typically found empirically by checking if straight lines in the world are straight in an undistorted image.
[in]*KThe camera calibration matrix, as a single array in row-major form, so K00, K01, K02, K10, K11, ...
[out]*x_pdThe distorted pixel x coordinate
[out]*y_pdThe distorted pixel y coordinate
Returns
Whether the transformation was successful

Definition at line 146 of file undistortion.c.

References Dhane_distortion(), and normalized_to_pixels().

Referenced by predict_flow_vectors(), and undistort_image_func().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void normalized_to_pixels ( float  x_n_,
float  y_n_,
float *  x_p,
float *  y_p,
const float *  K 
)

Transform normalized coordinates to pixel coordinates.

Parameters
[in]x_nThe undistorted normalized x coordinate
[in]y_nThe undistorted normalized y coordinate
[in]*KThe camera calibration matrix, as a single array in row-major form, so K00, K01, K02, K10, K11, ...
[out]*x_pThe pixel x coordinate
[out]*y_pThe pixel y coordinate

Definition at line 100 of file undistortion.c.

Referenced by normalized_coords_to_distorted_pixels().

+ Here is the caller graph for this function:

void pixels_to_normalized ( float  x_p,
float  y_p,
float *  x_n_,
float *  y_n_,
const float *  K 
)

Transform pixel coordinates to normalized coordinates.

Parameters
[out]*x_nThe undistorted normalized x coordinate
[out]*y_nThe undistorted normalized y coordinate
[in]*KThe camera calibration matrix, as a single array in row-major form, so K00, K01, K02, K10, K11, ...
[in]x_pThe pixel x coordinate
[in]y_pThe pixel y coordinate

Definition at line 113 of file undistortion.c.

Referenced by distorted_pixels_to_normalized_coords().

+ Here is the caller graph for this function: