PICCANTE  0.4
The hottest HDR imaging library!
nelder_mead_opt_radial_distortion.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_COMPUTER_VISION_NELDER_MEAD_OPT_RADIAL_DISTORTION_HPP
19 #define PIC_COMPUTER_VISION_NELDER_MEAD_OPT_RADIAL_DISTORTION_HPP
20 
21 #include "../util/matrix_3_x_3.hpp"
22 #include "../util/nelder_mead_opt_base.hpp"
23 
24 #ifndef PIC_DISABLE_EIGEN
25 #ifndef PIC_EIGEN_NOT_BUNDLED
26  #include "../externals/Eigen/Dense"
27 #else
28  #include <Eigen/Dense>
29 #endif
30 #endif
31 
32 namespace pic {
33 
34 #ifndef PIC_DISABLE_EIGEN
35 
37 {
38 public:
39 
40  std::vector< Eigen::Matrix34d > M;
41  std::vector< Eigen::Vector3d > *p3d;
42  std::vector< std::vector< Eigen::Vector2f > * > p2d;
43 
49  NelderMeadOptRadialDistortion(Eigen::Matrix34d &M0, Eigen::Matrix34d &M1,
50  std::vector< Eigen::Vector2f > *p2d_0,
51  std::vector< Eigen::Vector2f > *p2d_1,
52  std::vector< Eigen::Vector3d > *p3d) : NelderMeadOptBase()
53  {
54  this->M.push_back(M0);
55  this->M.push_back(M1);
56 
57  this->p2d.push_back(p2d_0);
58  this->p2d.push_back(p2d_1);
59  this->p3d = p3d;
60  }
61 
68  float function(float *x, unsigned int n)
69  {
70  float lambda = x[0];
71 
72  double err = 0.0;
73 
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);
78 
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;
84 
85  proj[0] /= proj[2];
86  proj[1] /= proj[2];
87 
88  double x_cx = (proj[0] - cx);
89  double y_cy = (proj[1] - cy);
90 
91  double dx = x_cx / fx;
92  double dy = y_cy / fy;
93  double rho_sq = dx * dx + dy * dy;
94 
95 
96  double factor = 1.0 / (1.0 + rho_sq * lambda);
97 
98  proj[0] = x_cx * factor + cx;
99  proj[1] = y_cy * factor + cy;
100 
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];
104 
105  err += d_err_x * d_err_x + d_err_y * d_err_y;
106  }
107  }
108 
109  err /= p3d->size();
110 
111  //err += 10.0f * lambda * lambda;
112 
113  return float(err);
114  }
115 };
116 
117 #endif
118 
119 }
120 
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