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