My Project
Optimization.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef OPTIMIZATION_H
25 #define OPTIMIZATION_H
26 
27 #include "Alvar.h"
28 
29 #include <opencv2/core/mat.hpp>
30 //#include <float.h>
31 
38 namespace alvar {
39 
44 class ALVAR_EXPORT Optimization
45 {
46 private:
47  void * estimate_param;
48  cv::Mat J;
49  cv::Mat JtJ;
50  cv::Mat W;
51  cv::Mat diag;
52  cv::Mat tmp;
53  cv::Mat err;
54  cv::Mat delta;
55  cv::Mat x_plus;
56  cv::Mat x_minus;
57  cv::Mat x_tmp1;
58  cv::Mat x_tmp2;
59  cv::Mat tmp_par;
60 
61  double CalcTukeyWeight(double residual, double c);
62  double CalcTukeyWeightSimple(double residual, double c);
63 
64  double lambda;
65 
66 public:
71  enum OptimizeMethod { GAUSSNEWTON, LEVENBERGMARQUARDT, TUKEY_LM };
72 
78  Optimization(int n_params, int n_meas);
79  ~Optimization();
80 
85  cv::Mat
87  {
88  return err;
89  }
90 
97  typedef void (*EstimateCallback)(cv::Mat &state, cv::Mat &projection, void *param);
98 
105  void CalcJacobian(cv::Mat &x, cv::Mat &J, EstimateCallback Estimate);
106 
119  double Optimize(cv::Mat & parameters,
120  cv::Mat & measurements,
121  double stop,
122  int max_iter,
123  EstimateCallback Estimate,
124  void * param = 0,
125  OptimizeMethod method = LEVENBERGMARQUARDT,
126  const cv::Mat & parameters_mask = cv::Mat(),
127  const cv::Mat & J_mat = cv::Mat(),
128  const cv::Mat & weights = cv::Mat());
129 };
130 
131 } // namespace alvar
132 
133 #endif
This file defines library export definitions, version numbers and build information.
Non-linear optimization routines. There are three methods implemented that include Gauss-Newton,...
Definition: Optimization.h:45
Optimization(int n_params, int n_meas)
Constructor.
OptimizeMethod
Selection between the algorithm used in optimization. Following should be noticed:
Definition: Optimization.h:71
cv::Mat GetErr()
Returns the current residual vector.
Definition: Optimization.h:86
void CalcJacobian(cv::Mat &x, cv::Mat &J, EstimateCallback Estimate)
Numerically differentiates and calculates the Jacobian around x.
double Optimize(cv::Mat &parameters, cv::Mat &measurements, double stop, int max_iter, EstimateCallback Estimate, void *param=0, OptimizeMethod method=LEVENBERGMARQUARDT, const cv::Mat &parameters_mask=cv::Mat(), const cv::Mat &J_mat=cv::Mat(), const cv::Mat &weights=cv::Mat())
Runs the optimization loop with selected parameters.
Main ALVAR namespace.
Definition: Alvar.h:174