|
1 | 1 | #ifndef VORTEX_UTILS_TYPES_HPP |
2 | 2 | #define VORTEX_UTILS_TYPES_HPP |
3 | 3 |
|
| 4 | +#include <cmath> |
4 | 5 | #include <eigen3/Eigen/Core> |
5 | 6 | #include <eigen3/Eigen/Dense> |
6 | 7 | #include <format> |
@@ -34,6 +35,16 @@ struct Twist; |
34 | 35 | */ |
35 | 36 | struct CameraIntrinsics; |
36 | 37 |
|
| 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 | + |
37 | 48 | struct PoseEuler { |
38 | 49 | double x{}; |
39 | 50 | double y{}; |
@@ -459,6 +470,39 @@ struct CameraIntrinsics { |
459 | 470 | } |
460 | 471 | }; |
461 | 472 |
|
| 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 | + |
462 | 506 | } // namespace vortex::utils::types |
463 | 507 |
|
464 | 508 | #endif // VORTEX_UTILS_TYPES_HPP |
0 commit comments