Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpTemplateTracker.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Template tracker.
32  *
33  * Authors:
34  * Amaury Dame
35  * Aurelien Yol
36  * Fabien Spindler
37  *
38  *****************************************************************************/
44 #ifndef vpTemplateTracker_hh
45 #define vpTemplateTracker_hh
46 
47 #include <math.h>
48 
49 #include <visp3/tt/vpTemplateTrackerHeader.h>
50 #include <visp3/tt/vpTemplateTrackerZone.h>
51 #include <visp3/tt/vpTemplateTrackerWarp.h>
52 #include <visp3/core/vpImageFilter.h>
53 
60 class VISP_EXPORT vpTemplateTracker
61 {
62  protected:
63  //traitement pyramidal
64  unsigned int nbLvlPyr; // If = 1, disable pyramidal usage
65  unsigned int l0Pyr;
67 
71  unsigned int templateSize;
72  unsigned int *templateSizePyr;
76  unsigned int templateSelectSize;
77 
78  #ifndef DOXYGEN_SHOULD_SKIP_THIS
79  vpTemplateTrackerPointSuppMIInv *ptTemplateSupp; //pour inverse et compo
80  vpTemplateTrackerPointSuppMIInv **ptTemplateSuppPyr; //pour inverse et compo
81  #endif
82 
87 
89 
99 
100  double gain;
103  bool blur;
104  bool useBrent;
105  unsigned int nbIterBrent;
106  unsigned int taillef;
107  double *fgG;
108  double *fgdG;
109  double ratioPixelIn;
110  int mod_i;
111  int mod_j;//variable de sampling de zone de reference
112  unsigned int nbParam ;
113  double lambdaDep ;
114  unsigned int iterationMax ;
115  //pour BFGS
116  unsigned int iterationGlobale;
117  //diverge is set to true if there is no more point in the tracked area
118  bool diverge;
119  unsigned int nbIteration;
122 
124  //Parametre de deplacement
127 
128  //temporary values for warping
131  //temporary derivative matrix
133 
137  vpTemplateTrackerZone zoneRef_; // Reference zone
138 
139 //private:
140 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
141 // vpTemplateTracker(const vpTemplateTracker &)
142 // : nbLvlPyr(0), l0Pyr(0), pyrInitialised(false), ptTemplate(NULL), ptTemplatePyr(NULL),
143 // ptTemplateInit(false), templateSize(0), templateSizePyr(NULL), ptTemplateSelect(NULL),
144 // ptTemplateSelectPyr(NULL), ptTemplateSelectInit(false), templateSelectSize(0),
145 // ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL), ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL),
146 // zoneTracked(NULL), zoneTrackedPyr(NULL), pyr_IDes(NULL), H(), Hdesire(), HdesirePyr(NULL),
147 // HLM(), HLMdesire(), HLMdesirePyr(NULL), HLMdesireInverse(), HLMdesireInversePyr(NULL),
148 // G(), gain(0), thresholdGradient(0), costFunctionVerification(false),
149 // blur(false), useBrent(false), nbIterBrent(0), taillef(0), fgG(NULL), fgdG(NULL),
150 // ratioPixelIn(0), mod_i(0), mod_j(0), nbParam(), lambdaDep(0), iterationMax(0),
151 // iterationGlobale(0), diverge(false), nbIteration(0), useCompositionnal(false),
152 // useInverse(false), Warp(NULL), p(), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(), zoneRef_()
153 // {
154 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
155 // }
156 // vpTemplateTracker &operator=(const vpTemplateTracker &){
157 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
158 // return *this;
159 // }
160 //#endif
161 
162  public:
165  : nbLvlPyr(0), l0Pyr(0), pyrInitialised(false), ptTemplate(NULL), ptTemplatePyr(NULL),
166  ptTemplateInit(false), templateSize(0), templateSizePyr(NULL), ptTemplateSelect(NULL),
167  ptTemplateSelectPyr(NULL), ptTemplateSelectInit(false), templateSelectSize(0),
168  ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL), ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL),
169  zoneTracked(NULL), zoneTrackedPyr(NULL), pyr_IDes(NULL), H(), Hdesire(), HdesirePyr(NULL),
170  HLM(), HLMdesire(), HLMdesirePyr(NULL), HLMdesireInverse(), HLMdesireInversePyr(NULL),
171  G(), gain(0), thresholdGradient(0), costFunctionVerification(false),
172  blur(false), useBrent(false), nbIterBrent(0), taillef(0), fgG(NULL), fgdG(NULL),
173  ratioPixelIn(0), mod_i(0), mod_j(0), nbParam(), lambdaDep(0), iterationMax(0),
174  iterationGlobale(0), diverge(false), nbIteration(0), useCompositionnal(false),
175  useInverse(false), Warp(NULL), p(), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(), zoneRef_()
176  {}
178  virtual ~vpTemplateTracker();
179 
180  void display(const vpImage<unsigned char> &I, const vpColor& col = vpColor::green, const unsigned int thickness=3);
181  void display(const vpImage<vpRGBa> &I, const vpColor& col = vpColor::green, const unsigned int thickness=3);
182 
183  bool getDiverge() const {return diverge;}
184  vpColVector getdp(){ return dp; }
185  vpColVector getG() const { return G; }
186  vpMatrix getH() const { return H; }
187  unsigned int getNbParam() const { return nbParam ; }
188  unsigned int getNbIteration() const { return nbIteration; }
189  vpColVector getp() const { return p;}
190  double getRatioPixelIn() const {return ratioPixelIn;}
191 
196  vpTemplateTrackerWarp *getWarp() const {return Warp;}
197 
201  vpTemplateTrackerZone getZoneRef() const { return zoneRef_; }
202 
203  void initClick(const vpImage<unsigned char> &I, bool delaunay=false);
204  void initFromPoints(const vpImage<unsigned char> &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false);
205  void initFromZone(const vpImage<unsigned char> &I, const vpTemplateTrackerZone& zone);
206 
207  void resetTracker();
208 
209  void setBlur(bool b){blur = b;}
210  void setCostFunctionVerification(bool b){costFunctionVerification = b;}
211  void setGain(double g){gain=g;}
212  void setGaussianFilterSize(unsigned int new_taill);
213  void setHDes(vpMatrix &tH){ Hdesire=tH; vpMatrix::computeHLM(Hdesire,lambdaDep,HLMdesire); HLMdesireInverse = HLMdesire.inverseByLU();}
218  void setIterationMax(const unsigned int &n) { iterationMax = n ; }
223  void setLambda(double l) { lambdaDep = l ; }
224  void setNbIterBrent(const unsigned int &b){nbIterBrent=b;}
225  void setp(const vpColVector &tp){ p=tp; diverge=false; iterationGlobale=0; }
233  void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1) {
234  nbLvlPyr = nlevels;
235  l0Pyr = level_to_stop;
236  if(l0Pyr >= nlevels){
237  std::cout << "Warning: level_to_stop: " << level_to_stop << " higher than level_to_start: " << nlevels-1 << " (nlevels-1)" <<std::endl;
238  std::cout << "Level to stop put to: " << nlevels-1 << std::endl;
239  l0Pyr = nlevels-1;
240  }
241  }
250  void setSampling(int sample_i,int sample_j){mod_i=sample_i; mod_j=sample_j;}
251  void setThresholdGradient(double threshold){thresholdGradient=threshold;}
253  void setUseBrent(bool b){useBrent = b;}
254 
255  void track(const vpImage<unsigned char> &I);
256  void trackRobust(const vpImage<unsigned char> &I);
257 
258  protected:
259 
260  void computeOptimalBrentGain(const vpImage<unsigned char> &I,vpColVector &tp,double tMI,vpColVector &direction,double &alpha);
261  virtual double getCost(const vpImage<unsigned char> &I, const vpColVector &tp) = 0;
263  virtual void initHessienDesired(const vpImage<unsigned char> &I)=0;
264  virtual void initHessienDesiredPyr(const vpImage<unsigned char> &I);
265  virtual void initPyramidal(unsigned int nbLvl,unsigned int l0);
266  void initTracking(const vpImage<unsigned char>& I,vpTemplateTrackerZone &zone);
267  virtual void initTrackingPyr(const vpImage<unsigned char>& I,vpTemplateTrackerZone &zone);
268  virtual void trackNoPyr(const vpImage<unsigned char> &I) = 0;
269  virtual void trackPyr(const vpImage<unsigned char> &I);
270 };
271 #endif
272 
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
vpColVector getG() const
void setSampling(int sample_i, int sample_j)
void setNbIterBrent(const unsigned int &b)
vpMatrix getH() const
unsigned int templateSelectSize
void getGaussianBluredImage(const vpImage< unsigned char > &I)
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerPoint ** ptTemplatePyr
void setHDes(vpMatrix &tH)
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void setGain(double g)
void setIterationMax(const unsigned int &n)
void setUseBrent(bool b)
vpMatrix * HLMdesireInversePyr
vpTemplateTracker()
Default constructor.
vpImage< double > BI
static const vpColor green
Definition: vpColor.h:166
vpColVector getp() const
unsigned int templateSize
unsigned int iterationMax
vpTemplateTrackerZone * zoneTrackedPyr
vpTemplateTrackerZone zoneRef_
vpImage< double > dIx
unsigned int getNbParam() const
vpImage< double > dIy
unsigned int getNbIteration() const
unsigned int iterationGlobale
unsigned int nbIteration
double getRatioPixelIn() const
unsigned int * templateSizePyr
unsigned int nbLvlPyr
vpTemplateTrackerPointCompo * ptTemplateCompo
bool getDiverge() const
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setLambda(double l)
vpTemplateTrackerZone * zoneTracked
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, const bool convolve=false)
vpTemplateTrackerZone getZoneRef() const
vpImage< unsigned char > * pyr_IDes
void setp(const vpColVector &tp)
vpTemplateTrackerWarp * Warp
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
Definition: vpMatrix.cpp:3525
unsigned int nbIterBrent
vpTemplateTrackerPointCompo ** ptTemplateCompoPyr
void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1)
vpTemplateTrackerWarp * getWarp() const
void setThresholdGradient(double threshold)
void setCostFunctionVerification(bool b)