Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpTemplateTrackerMI.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Example of template tracking.
33  *
34  * Authors:
35  * Amaury Dame
36  * Aurelien Yol
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 #ifndef vpTemplateTrackerMI_hh
41 #define vpTemplateTrackerMI_hh
42 
43 #include <visp3/core/vpConfig.h>
44 
45 #include <visp3/core/vpImageFilter.h>
46 #include <visp3/tt/vpTemplateTracker.h>
47 #include <visp3/tt/vpTemplateTrackerHeader.h>
48 
53 class VISP_EXPORT vpTemplateTrackerMI : public vpTemplateTracker
54 {
55 public:
57  typedef enum {
58  HESSIAN_NONSECOND = -1,
63  HESSIAN_NEW
65 
67  typedef enum { USE_HESSIEN_NORMAL, USE_HESSIEN_DESIRE, USE_HESSIEN_BEST_COND } vpHessienType;
68 
70  typedef enum { BSPLINE_THIRD_ORDER = 3, BSPLINE_FOURTH_ORDER = 4 } vpBsplineType;
71 
72 protected:
73  vpHessienType hessianComputation;
74  vpHessienApproximationType ApproxHessian;
75  double lambda;
76 
77  double *temp;
78  double *Prt;
79  double *dPrt;
80  double *Pt;
81  double *Pr;
82  double *d2Prt;
83  double *PrtTout;
84  double *dprtemp;
85 
86  double *PrtD;
87  double *dPrtD;
89 
90  int bspline;
91  // Nombre de couleur concidere dans l'histogramme
92  int Nc;
93  int Ncb;
94 
98 
101 
104 
107 
108  // Internal vars for computeHessienNormalized()
109  std::vector<double> m_du;
110  std::vector<double> m_dv;
111  std::vector<double> m_A;
112  std::vector<double> m_dB;
113  std::vector< std::vector<double> > m_d2u;
114  std::vector< std::vector<double> > m_d2v;
115  std::vector< std::vector<double> > m_dA;
116 
117 protected:
118  void computeGradient();
119  void computeHessien(vpMatrix &H);
120  void computeHessienNormalized(vpMatrix &H);
121  void computeMI(double &MI);
122  void computeProba(int &nbpoint);
123 
124  double getCost(const vpImage<unsigned char> &I, const vpColVector &tp);
125  double getCost(const vpImage<unsigned char> &I) { return getCost(I, p); }
126  double getNormalizedCost(const vpImage<unsigned char> &I, const vpColVector &tp);
127  double getNormalizedCost(const vpImage<unsigned char> &I) { return getNormalizedCost(I, p); }
128  virtual void initHessienDesired(const vpImage<unsigned char> &I) = 0;
129  virtual void trackNoPyr(const vpImage<unsigned char> &I) = 0;
130  void zeroProbabilities();
131 
132  // private:
133  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
134  // vpTemplateTrackerMI(const vpTemplateTrackerMI &)
135  // : vpTemplateTracker(), hessianComputation(USE_HESSIEN_NORMAL),
136  // ApproxHessian(HESSIAN_0), lambda(0),
137  // temp(NULL), Prt(NULL), dPrt(NULL), Pt(NULL), Pr(NULL), d2Prt(NULL),
138  // PrtTout(NULL), dprtemp(NULL), PrtD(NULL), dPrtD(NULL),
139  // influBspline(0), bspline(0), Nc(0), Ncb(0), d2Ix(), d2Iy(), d2Ixy(),
140  // MI_preEstimation(0), MI_postEstimation(0), NMI_preEstimation(0),
141  // NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false)
142  // {
143  // throw vpException(vpException::functionNotImplementedError, "Not
144  // implemented!");
145  // }
146  // vpTemplateTrackerMI &operator=(const vpTemplateTrackerMI &){
147  // throw vpException(vpException::functionNotImplementedError, "Not
148  // implemented!"); return *this;
149  // }
150  //#endif
151 
152 public:
153  // constructeur
156  : vpTemplateTracker(), hessianComputation(USE_HESSIEN_NORMAL), ApproxHessian(HESSIAN_0), lambda(0), temp(NULL),
157  Prt(NULL), dPrt(NULL), Pt(NULL), Pr(NULL), d2Prt(NULL), PrtTout(NULL), dprtemp(NULL), PrtD(NULL), dPrtD(NULL),
158  influBspline(0), bspline(0), Nc(0), Ncb(0), d2Ix(), d2Iy(), d2Ixy(), MI_preEstimation(0), MI_postEstimation(0),
159  NMI_preEstimation(0), NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false),
160  m_du(), m_dv(), m_A(), m_dB(), m_d2u(), m_d2v(), m_dA()
161  {
162  }
164  virtual ~vpTemplateTrackerMI();
165  vpMatrix getCovarianceMatrix() const { return covarianceMatrix; }
166  double getMI() const { return MI_postEstimation; }
167  double getMI(const vpImage<unsigned char> &I, int &nc, const int &bspline, vpColVector &tp);
168  double getMI256(const vpImage<unsigned char> &I, const vpColVector &tp);
169  double getNMI() const { return NMI_postEstimation; }
170  // initialisation du Hessien en position desiree
171  void setApprocHessian(vpHessienApproximationType approx) { ApproxHessian = approx; }
172  void setCovarianceComputation(const bool &flag) { computeCovariance = flag; }
173  void setHessianComputation(vpHessienType type) { hessianComputation = type; }
174  void setBspline(const vpBsplineType &newbs);
175  void setLambda(double _l) { lambda = _l; }
176  void setNc(int newNc);
177 };
178 
179 #endif
vpMatrix getCovarianceMatrix() const
vpTemplateTrackerMI()
Default constructor.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
void setLambda(double _l)
std::vector< double > m_dv
void setApprocHessian(vpHessienApproximationType approx)
std::vector< std::vector< double > > m_d2u
vpImage< double > d2Ix
std::vector< double > m_dB
vpHessienApproximationType ApproxHessian
std::vector< double > m_A
double getCost(const vpImage< unsigned char > &I)
std::vector< std::vector< double > > m_d2v
void setHessianComputation(vpHessienType type)
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
std::vector< double > m_du
virtual double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)=0
double getNormalizedCost(const vpImage< unsigned char > &I)
vpImage< double > d2Iy
std::vector< std::vector< double > > m_dA
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void setCovarianceComputation(const bool &flag)
vpImage< double > d2Ixy
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
vpHessienType hessianComputation