Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpTemplateTrackerMI.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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  *
38 *****************************************************************************/
39 #ifndef vpTemplateTrackerMI_hh
40 #define vpTemplateTrackerMI_hh
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #include <visp3/core/vpImageFilter.h>
45 #include <visp3/tt/vpTemplateTracker.h>
46 #include <visp3/tt/vpTemplateTrackerHeader.h>
47 
52 class VISP_EXPORT vpTemplateTrackerMI : public vpTemplateTracker
53 {
54 public:
56  typedef enum {
57  HESSIAN_NONSECOND = -1,
62  HESSIAN_NEW
63  } vpHessienApproximationType;
64 
66  typedef enum { USE_HESSIEN_NORMAL, USE_HESSIEN_DESIRE, USE_HESSIEN_BEST_COND } vpHessienType;
67 
69  typedef enum { BSPLINE_THIRD_ORDER = 3, BSPLINE_FOURTH_ORDER = 4 } vpBsplineType;
70 
71 protected:
74  double lambda;
75 
76  double *temp;
77  double *Prt;
78  double *dPrt;
79  double *Pt;
80  double *Pr;
81  double *d2Prt;
82  double *PrtTout;
83  double *dprtemp;
84 
85  double *PrtD;
86  double *dPrtD;
88 
89  int bspline;
90  // Nombre de couleur concidere dans l'histogramme
91  int Nc;
92  int Ncb;
93 
97 
100 
103 
106 
107  // Internal vars for computeHessienNormalized()
108  std::vector<double> m_du;
109  std::vector<double> m_dv;
110  std::vector<double> m_A;
111  std::vector<double> m_dB;
112  std::vector<std::vector<double> > m_d2u;
113  std::vector<std::vector<double> > m_d2v;
114  std::vector<std::vector<double> > m_dA;
115 
116 protected:
117  void computeGradient();
118  void computeHessien(vpMatrix &H);
119  void computeHessienNormalized(vpMatrix &H);
120  void computeMI(double &MI);
121  void computeProba(int &nbpoint);
122 
123  double getCost(const vpImage<unsigned char> &I, const vpColVector &tp);
124  double getCost(const vpImage<unsigned char> &I) { return getCost(I, p); }
125  double getNormalizedCost(const vpImage<unsigned char> &I, const vpColVector &tp);
126  double getNormalizedCost(const vpImage<unsigned char> &I) { return getNormalizedCost(I, p); }
127  virtual void initHessienDesired(const vpImage<unsigned char> &I) = 0;
128  virtual void trackNoPyr(const vpImage<unsigned char> &I) = 0;
129  void zeroProbabilities();
130 
131  // private:
132  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
133  // vpTemplateTrackerMI(const vpTemplateTrackerMI &)
134  // : vpTemplateTracker(), hessianComputation(USE_HESSIEN_NORMAL),
135  // ApproxHessian(HESSIAN_0), lambda(0),
136  // temp(NULL), Prt(NULL), dPrt(NULL), Pt(NULL), Pr(NULL), d2Prt(NULL),
137  // PrtTout(NULL), dprtemp(NULL), PrtD(NULL), dPrtD(NULL),
138  // influBspline(0), bspline(0), Nc(0), Ncb(0), d2Ix(), d2Iy(), d2Ixy(),
139  // MI_preEstimation(0), MI_postEstimation(0), NMI_preEstimation(0),
140  // NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false)
141  // {
142  // throw vpException(vpException::functionNotImplementedError, "Not
143  // implemented!");
144  // }
145  // vpTemplateTrackerMI &operator=(const vpTemplateTrackerMI &){
146  // throw vpException(vpException::functionNotImplementedError, "Not
147  // implemented!"); return *this;
148  // }
149  //#endif
150 
151 public:
152  // constructeur
155  : vpTemplateTracker(), hessianComputation(USE_HESSIEN_NORMAL), ApproxHessian(HESSIAN_0), lambda(0), temp(NULL),
156  Prt(NULL), dPrt(NULL), Pt(NULL), Pr(NULL), d2Prt(NULL), PrtTout(NULL), dprtemp(NULL), PrtD(NULL), dPrtD(NULL),
157  influBspline(0), bspline(0), Nc(0), Ncb(0), d2Ix(), d2Iy(), d2Ixy(), MI_preEstimation(0), MI_postEstimation(0),
158  NMI_preEstimation(0), NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false), m_du(), m_dv(), m_A(),
159  m_dB(), m_d2u(), m_d2v(), m_dA()
160  {
161  }
163  virtual ~vpTemplateTrackerMI();
164  vpMatrix getCovarianceMatrix() const { return covarianceMatrix; }
165  double getMI() const { return MI_postEstimation; }
166  double getMI(const vpImage<unsigned char> &I, int &nc, const int &bspline, vpColVector &tp);
167  double getMI256(const vpImage<unsigned char> &I, const vpColVector &tp);
168  double getNMI() const { return NMI_postEstimation; }
169  // initialisation du Hessien en position desiree
170  void setApprocHessian(vpHessienApproximationType approx) { ApproxHessian = approx; }
171  void setCovarianceComputation(const bool &flag) { computeCovariance = flag; }
172  void setHessianComputation(vpHessienType type) { hessianComputation = type; }
173  void setBspline(const vpBsplineType &newbs);
174  void setLambda(double _l) { lambda = _l; }
175  void setNc(int newNc);
176 };
177 
178 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:167
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:152
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)
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
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
vpMatrix getCovarianceMatrix() const
std::vector< std::vector< double > > m_dA
vpImage< double > d2Iy
void setLambda(double _l)
void setCovarianceComputation(const bool &flag)
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
std::vector< double > m_A
virtual double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)=0