Skip to content

Commit 94a36ca

Browse files
committed
distortion model and forward distortion function
1 parent 3a02fdb commit 94a36ca

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

vortex_utils/include/vortex/utils/types.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef VORTEX_UTILS_TYPES_HPP
22
#define VORTEX_UTILS_TYPES_HPP
33

4+
#include <cmath>
45
#include <eigen3/Eigen/Core>
56
#include <eigen3/Eigen/Dense>
67
#include <format>
@@ -34,6 +35,16 @@ struct Twist;
3435
*/
3536
struct CameraIntrinsics;
3637

38+
/**
39+
* @brief Brown-Conrady (also referred to as Plumb Bob) distortion model that
40+
* models radial and tangential distortion for a pinhole camera model.
41+
* Uses the distortion coefficients (k1, k2, p1, p2 ,k3) where k_i are the
42+
* radial terms and p_i are the tangential terms.
43+
* Implements the forward distortion model, i.e. the mapping from
44+
* undistorted normalized coordinates to distorted normalized coordinates.
45+
*/
46+
struct CameraDistortionModel;
47+
3748
struct PoseEuler {
3849
double x{};
3950
double y{};
@@ -459,6 +470,39 @@ struct CameraIntrinsics {
459470
}
460471
};
461472

473+
struct CameraDistortionModel {
474+
double k1{0.0};
475+
double k2{0.0};
476+
double p1{0.0};
477+
double p2{0.0};
478+
double k3{0.0};
479+
480+
/**
481+
* @brief Distort a point in normalized image coordinates following the
482+
* Brown-Conrady forward distortion model. This matches the OpenCV
483+
* convention.
484+
* @param point Eigen::Vector2d representing and undistorted point in
485+
* normalized image coordinates.
486+
* @return 2D distorted point in normalized image coordinates.
487+
*/
488+
Eigen::Vector2d distort_normalized(const Eigen::Vector2d& point) const {
489+
const double x = point.x();
490+
const double y = point.y();
491+
const double r2 = x * x + y * y;
492+
const double r4 = r2 * r2;
493+
const double r6 = r4 * r2;
494+
495+
const double r_dist = 1.0 + k1 * r2 + k2 * r4 + k3 * r6;
496+
const double t_dist_x = 2.0 * p1 * x * y + p2 * (r2 + 2.0 * x * x);
497+
const double t_dist_y = p1 * (r2 + 2.0 * y * y) + 2.0 * p2 * x * y;
498+
499+
const double x_dist = r_dist * x + t_dist_x;
500+
const double y_dist = r_dist * y + t_dist_y;
501+
502+
return {x_dist, y_dist};
503+
}
504+
};
505+
462506
} // namespace vortex::utils::types
463507

464508
#endif // VORTEX_UTILS_TYPES_HPP

0 commit comments

Comments
 (0)