52 #include <glog/logging.h>
79 image_width_(image_width),
80 image_height_(image_height),
96 int image_width,
int image_height,
97 double f_u,
double f_v,
double c_u,
98 double c_v,
double k1,
double k2,
double k3,
100 : image_left_(image_left),
101 image_top_(image_top),
102 image_width_(image_width),
103 image_height_(image_height),
271 return in_cols && in_rows;
277 double *v_distorted)
const {
278 CHECK_NOTNULL(u_distorted);
279 CHECK_NOTNULL(v_distorted);
282 if (cz < 0.0)
return false;
286 const double u_normalized = cx / cz;
287 const double v_normalized = cy / cz;
289 return DirectionToImage(u_normalized, v_normalized, u_distorted, v_distorted);
295 double *v_distorted)
const {
296 CHECK_NOTNULL(u_distorted);
297 CHECK_NOTNULL(v_distorted);
300 double u = 0.0, v = 0.0;
301 Distort(u_normalized, v_normalized, &u, &v);
310 *u_distorted = p_out(0);
311 *v_distorted = p_out(1);
318 double *u_normalized,
319 double *v_normalized)
const {
320 CHECK_NOTNULL(u_normalized);
321 CHECK_NOTNULL(v_normalized);
324 Vector3d p_distorted;
325 p_distorted << u_distorted, v_distorted, 1.0;
332 Undistort(p(0), p(1), u_normalized, v_normalized);
337 double *v_distorted)
const {
338 CHECK_NOTNULL(u_distorted);
339 CHECK_NOTNULL(v_distorted);
343 const double r_sq = u * u + v * v;
344 const double radial_dist =
345 1.0 +
k1_ * r_sq +
k2_ * r_sq * r_sq +
k5_ * r_sq * r_sq * r_sq;
350 if (radial_dist < 0.85 || radial_dist > 1.15) {
354 *u_distorted = u / sqrt(r_sq) * radius;
355 *v_distorted = v / sqrt(r_sq) * radius;
358 const double dx0 = 2.0 *
k3_ * u * v +
k4_ * (r_sq + 2.0 * u * u);
359 const double dx1 =
k3_ * (r_sq + 2.0 * v * v) + 2.0 *
k4_ * u * v;
362 *u_distorted = radial_dist * u + dx0;
363 *v_distorted = radial_dist * v + dx1;
369 double *u,
double *v,
int iterations)
const {
375 double u_refine = u_distorted;
376 double v_refine = v_distorted;
377 for (
int i = 0; i < iterations; ++i) {
378 const double r_sq = u_refine * u_refine + v_refine * v_refine;
379 const double dx0 = 2.0 *
k3_ * u_refine * v_refine +
380 k4_ * (r_sq + 2.0 * u_refine * u_refine);
381 const double dx1 =
k3_ * (r_sq + 2.0 * v_refine * v_refine) +
382 2.0 *
k4_ * u_refine * v_refine;
383 u_refine = u_distorted - dx0;
384 v_refine = v_distorted - dx1;
double VerticalFOV() const
void ImageToDirection(double u_distorted, double v_distorted, double *u_normalized, double *v_normalized) const
void SetImageLeft(int image_left)
void SetVerticalFOV(double vertical_fov)
bool DirectionToImage(double u_normalized, double v_normalized, double *u_distorted, double *v_distorted) const
void SetImageHeight(int image_height)
bool PointInImage(double u, double v) const
void SetK(double k1, double k2, double k3, double k4, double k5)
void SetImageWidth(int image_width)
void Distort(double u, double v, double *u_distorted, double *v_distorted) const
void SetImageTop(int image_top)
void Undistort(double u_distorted, double v_distorted, double *u, double *v, int iterations=10) const
double HorizontalFOV() const
void SetHorizontalFOV(double horizontal_fov)
bool CameraToImage(double cx, double cy, double cz, double *u_distorted, double *v_distorted) const