Visual Servoing Platform  version 3.6.1 under development (2024-04-22)
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 
46 class VISP_EXPORT vpTemplateTrackerMI : public vpTemplateTracker
47 {
48 public:
50  typedef enum
51  {
52  HESSIAN_NONSECOND = -1,
57  HESSIAN_NEW
58  } vpHessienApproximationType;
59 
61  typedef enum { USE_HESSIEN_NORMAL, USE_HESSIEN_DESIRE, USE_HESSIEN_BEST_COND } vpHessienType;
62 
64  typedef enum { BSPLINE_THIRD_ORDER = 3, BSPLINE_FOURTH_ORDER = 4 } vpBsplineType;
65 
66 protected:
69  double lambda;
70 
71  double *temp;
72  double *Prt;
73  double *dPrt;
74  double *Pt;
75  double *Pr;
76  double *d2Prt;
77  double *PrtTout;
78  double *dprtemp;
79 
80  double *PrtD;
81  double *dPrtD;
83 
84  int bspline;
85  // Nombre de couleur concidere dans l'histogramme
86  int Nc;
87  int Ncb;
88 
92 
95 
98 
101 
102  // Internal vars for computeHessienNormalized()
103  std::vector<double> m_du;
104  std::vector<double> m_dv;
105  std::vector<double> m_A;
106  std::vector<double> m_dB;
107  std::vector<std::vector<double> > m_d2u;
108  std::vector<std::vector<double> > m_d2v;
109  std::vector<std::vector<double> > m_dA;
110 
111 protected:
112  void computeGradient();
113  void computeHessien(vpMatrix &H);
114  void computeHessienNormalized(vpMatrix &H);
115  void computeMI(double &MI);
116  void computeProba(int &nbpoint);
117 
118  double getCost(const vpImage<unsigned char> &I, const vpColVector &tp) vp_override;
119  double getCost(const vpImage<unsigned char> &I) { return getCost(I, p); }
120  double getNormalizedCost(const vpImage<unsigned char> &I, const vpColVector &tp);
121  double getNormalizedCost(const vpImage<unsigned char> &I) { return getNormalizedCost(I, p); }
122  void zeroProbabilities();
123 
124  // private:
125  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
126  // vpTemplateTrackerMI(const vpTemplateTrackerMI &)
127  // : vpTemplateTracker(), hessianComputation(USE_HESSIEN_NORMAL),
128  // ApproxHessian(HESSIAN_0), lambda(0),
129  // temp(nullptr), Prt(nullptr), dPrt(nullptr), Pt(nullptr), Pr(nullptr), d2Prt(nullptr),
130  // PrtTout(nullptr), dprtemp(nullptr), PrtD(nullptr), dPrtD(nullptr),
131  // influBspline(0), bspline(0), Nc(0), Ncb(0), d2Ix(), d2Iy(), d2Ixy(),
132  // MI_preEstimation(0), MI_postEstimation(0), NMI_preEstimation(0),
133  // NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false)
134  // {
135  // throw vpException(vpException::functionNotImplementedError, "Not
136  // implemented!");
137  // }
138  // vpTemplateTrackerMI &operator=(const vpTemplateTrackerMI &){
139  // throw vpException(vpException::functionNotImplementedError, "Not
140  // implemented!"); return *this;
141  // }
142  //#endif
143 
144 public:
147  : vpTemplateTracker(), hessianComputation(USE_HESSIEN_NORMAL), ApproxHessian(HESSIAN_0), lambda(0), temp(nullptr),
148  Prt(nullptr), dPrt(nullptr), Pt(nullptr), Pr(nullptr), d2Prt(nullptr), PrtTout(nullptr), dprtemp(nullptr), PrtD(nullptr), dPrtD(nullptr),
149  influBspline(0), bspline(0), Nc(0), Ncb(0), d2Ix(), d2Iy(), d2Ixy(), MI_preEstimation(0), MI_postEstimation(0),
150  NMI_preEstimation(0), NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false), m_du(), m_dv(), m_A(),
151  m_dB(), m_d2u(), m_d2v(), m_dA()
152  { }
154  virtual ~vpTemplateTrackerMI() vp_override;
155  vpMatrix getCovarianceMatrix() const { return covarianceMatrix; }
156  double getMI() const { return MI_postEstimation; }
157  double getMI(const vpImage<unsigned char> &I, int &nc, const int &bspline, vpColVector &tp);
158  double getMI256(const vpImage<unsigned char> &I, const vpColVector &tp);
159  double getNMI() const { return NMI_postEstimation; }
160  // initialisation du Hessien en position desiree
161  void setApprocHessian(vpHessienApproximationType approx) { ApproxHessian = approx; }
162  void setCovarianceComputation(const bool &flag) { computeCovariance = flag; }
163  void setHessianComputation(vpHessienType type) { hessianComputation = type; }
164  void setBspline(const vpBsplineType &newbs);
165  void setLambda(double _l) { lambda = _l; }
166  void setNc(int newNc);
167 };
168 
169 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
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