21#ifndef LIBMV_SIMPLE_PIPELINE_DISTORTION_MODELS_H_
22#define LIBMV_SIMPLE_PIPELINE_DISTORTION_MODELS_H_
39 const double focal_length_y,
40 const double principal_point_x,
41 const double principal_point_y,
50 double* normalized_y);
58 const T& focal_length_y,
59 const T& principal_point_x,
60 const T& principal_point_y,
66 const T& normalized_x,
67 const T& normalized_y,
77 T r_coeff = (
T(1) + k1 * r2 + k2 * r4 + k3 * r6);
78 T xd = x * r_coeff +
T(2) * p1 * x * y + p2 * (r2 +
T(2) * x *
x);
79 T yd = y * r_coeff +
T(2) * p2 * x * y + p1 * (r2 +
T(2) * y *
y);
82 *image_x = focal_length_x * xd + principal_point_x;
83 *image_y = focal_length_y * yd + principal_point_y;
92 const double focal_length_y,
93 const double principal_point_x,
94 const double principal_point_y,
100 double* normalized_y);
110 const T& focal_length_y,
111 const T& principal_point_x,
112 const T& principal_point_y,
115 const T& normalized_x,
116 const T& normalized_y,
121 T r2 = x * x + y *
y;
124 T xd = x / (
T(1) + k1 * r2 + k2 * r4);
125 T yd = y / (
T(1) + k1 * r2 + k2 * r4);
128 *image_x = focal_length_x * xd + principal_point_x;
129 *image_y = focal_length_y * yd + principal_point_y;
139 const T& focal_length_y,
140 const T& principal_point_x,
141 const T& principal_point_y,
165 const double max_half_image_size = max_image_size * 0.5;
167 if (max_half_image_size == 0.0) {
168 *normalized_x = image_x * max_half_image_size / focal_length_x;
169 *normalized_y = image_y * max_half_image_size / focal_length_y;
173 const T xd = (image_x - principal_point_x) / max_half_image_size;
174 const T yd = (image_y - principal_point_y) / max_half_image_size;
176 T rd2 = xd * xd + yd * yd;
178 T r_coeff =
T(1) / (
T(1) + k1 * rd2 + k2 * rd4);
182 *normalized_x = xu * max_half_image_size / focal_length_x;
183 *normalized_y = yu * max_half_image_size / focal_length_y;
193 const double focal_length_y,
194 const double principal_point_x,
195 const double principal_point_y,
200 const double normalized_x,
201 const double normalized_y,
209 const double focal_length_y,
210 const double principal_point_x,
211 const double principal_point_y,
218 const double image_x,
219 const double image_y,
220 double* normalized_x,
221 double* normalized_y);
225 const T& focal_length_y,
226 const T& principal_point_x,
227 const T& principal_point_y,
234 const T& normalized_x,
235 const T& normalized_y,
244 T xy2 =
T(2) * x *
y;
246 T r_coeff =
T(1) + (((k4 * r2 + k3) * r2 + k2) * r2 + k1) * r2;
247 T tx = p1 * (r2 +
T(2) * x2) + p2 * xy2;
248 T ty = p2 * (r2 +
T(2) * y2) + p1 * xy2;
249 T xd = x * r_coeff + tx;
250 T yd = y * r_coeff + ty;
253 *image_x = focal_length_x * xd + principal_point_x;
254 *image_y = focal_length_y * yd + principal_point_y;
static constexpr int image_width
static constexpr int image_height
void InvertNukeDistortionModel(const T &focal_length_x, const T &focal_length_y, const T &principal_point_x, const T &principal_point_y, const int image_width, const int image_height, const T &k1, const T &k2, const T &image_x, const T &image_y, T *normalized_x, T *normalized_y)
void InvertPolynomialDistortionModel(const double focal_length_x, const double focal_length_y, const double principal_point_x, const double principal_point_y, const double k1, const double k2, const double k3, const double p1, const double p2, const double image_x, const double image_y, double *normalized_x, double *normalized_y)
void ApplyPolynomialDistortionModel(const T &focal_length_x, const T &focal_length_y, const T &principal_point_x, const T &principal_point_y, const T &k1, const T &k2, const T &k3, const T &p1, const T &p2, const T &normalized_x, const T &normalized_y, T *image_x, T *image_y)
void ApplyDivisionDistortionModel(const T &focal_length_x, const T &focal_length_y, const T &principal_point_x, const T &principal_point_y, const T &k1, const T &k2, const T &normalized_x, const T &normalized_y, T *image_x, T *image_y)
void ApplyNukeDistortionModel(const double focal_length_x, const double focal_length_y, const double principal_point_x, const double principal_point_y, const int image_width, const int image_height, const double k1, const double k2, const double normalized_x, const double normalized_y, double *image_x, double *image_y)
void InvertBrownDistortionModel(const double focal_length_x, const double focal_length_y, const double principal_point_x, const double principal_point_y, const double k1, const double k2, const double k3, const double k4, const double p1, const double p2, const double image_x, const double image_y, double *normalized_x, double *normalized_y)
void InvertDivisionDistortionModel(const double focal_length_x, const double focal_length_y, const double principal_point_x, const double principal_point_y, const double k1, const double k2, const double image_x, const double image_y, double *normalized_x, double *normalized_y)
@ DISTORTION_MODEL_POLYNOMIAL
@ DISTORTION_MODEL_DIVISION
void ApplyBrownDistortionModel(const T &focal_length_x, const T &focal_length_y, const T &principal_point_x, const T &principal_point_y, const T &k1, const T &k2, const T &k3, const T &k4, const T &p1, const T &p2, const T &normalized_x, const T &normalized_y, T *image_x, T *image_y)