18 #ifndef PIC_COMPUTER_VISION_NELDER_MEAD_OPT_RADIAL_DISTORTION_HPP 19 #define PIC_COMPUTER_VISION_NELDER_MEAD_OPT_RADIAL_DISTORTION_HPP 21 #include "../util/matrix_3_x_3.hpp" 22 #include "../util/nelder_mead_opt_base.hpp" 24 #ifndef PIC_DISABLE_EIGEN 25 #ifndef PIC_EIGEN_NOT_BUNDLED 26 #include "../externals/Eigen/Dense" 28 #include <Eigen/Dense> 34 #ifndef PIC_DISABLE_EIGEN 40 std::vector< Eigen::Matrix34d >
M;
41 std::vector< Eigen::Vector3d > *
p3d;
42 std::vector< std::vector< Eigen::Vector2f > * >
p2d;
50 std::vector< Eigen::Vector2f > *p2d_0,
51 std::vector< Eigen::Vector2f > *p2d_1,
54 this->M.push_back(M0);
55 this->M.push_back(M1);
57 this->p2d.push_back(p2d_0);
58 this->p2d.push_back(p2d_1);
68 float function(
float *x,
unsigned int n)
74 double cx =
M[0](0,2);
75 double cy =
M[0](1,2);
76 double fx =
M[0](0, 0);
77 double fy =
M[0](1, 1);
79 for(
unsigned int i = 0; i <
M.size(); i++) {
80 for(
unsigned int j = 0; j <
p3d->size(); j++) {
81 Eigen::Vector3d tmp =
p3d->at(j);
82 Eigen::Vector4d point = Eigen::Vector4d(tmp[0], tmp[1], tmp[2], 1.0);
83 Eigen::Vector3d proj =
M[i] * point;
88 double x_cx = (proj[0] - cx);
89 double y_cy = (proj[1] - cy);
91 double dx = x_cx / fx;
92 double dy = y_cy / fy;
93 double rho_sq = dx * dx + dy * dy;
96 double factor = 1.0 / (1.0 + rho_sq *
lambda);
98 proj[0] = x_cx * factor + cx;
99 proj[1] = y_cy * factor + cy;
101 Eigen::Vector2f tmp2d =
p2d[i]->at(j);
102 double d_err_x = tmp2d[0] - proj[0];
103 double d_err_y = tmp2d[1] - proj[1];
105 err += d_err_x * d_err_x + d_err_y * d_err_y;
121 #endif // PIC_COMPUTER_VISION_NELDER_MEAD_OPT_RADIAL_DISTORTION_HPP std::vector< Eigen::Matrix34d > M
Definition: nelder_mead_opt_radial_distortion.hpp:40
float lambda
Definition: nelder_mead_opt_base.hpp:36
NelderMeadOptRadialDistortion(Eigen::Matrix34d &M0, Eigen::Matrix34d &M1, std::vector< Eigen::Vector2f > *p2d_0, std::vector< Eigen::Vector2f > *p2d_1, std::vector< Eigen::Vector3d > *p3d)
NelderMeadOptRadialDistortion.
Definition: nelder_mead_opt_radial_distortion.hpp:49
The NelderMeadOptBase class.
Definition: nelder_mead_opt_base.hpp:31
Definition: bilateral_separation.hpp:25
Definition: nelder_mead_opt_radial_distortion.hpp:36
std::vector< Eigen::Vector3d > * p3d
Definition: nelder_mead_opt_radial_distortion.hpp:41
std::vector< std::vector< Eigen::Vector2f > *> p2d
Definition: nelder_mead_opt_radial_distortion.hpp:42