ViSP  2.10.0
vpTemplateTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTracker.h 5113 2015-01-05 08:00:50Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Template tracker.
35  *
36  * Authors:
37  * Amaury Dame
38  * Aurelien Yol
39  * Fabien Spindler
40  *
41  *****************************************************************************/
47 #ifndef vpTemplateTracker_hh
48 #define vpTemplateTracker_hh
49 
50 #include <math.h>
51 
52 #include <visp/vpTemplateTrackerHeader.h>
53 #include <visp/vpTemplateTrackerZone.h>
54 #include <visp/vpTemplateTrackerWarp.h>
55 #include <visp/vpImageFilter.h>
56 
57 class VISP_EXPORT vpTemplateTracker
58 {
59  protected:
60  //traitement pyramidal
61  unsigned int nbLvlPyr; // If = 1, disable pyramidal usage
62  unsigned int l0Pyr;
64 
68  unsigned int templateSize;
69  unsigned int *templateSizePyr;
73  unsigned int templateSelectSize;
74 
75  #ifndef DOXYGEN_SHOULD_SKIP_THIS
76  vpTemplateTrackerPointSuppMIInv *ptTemplateSupp; //pour inverse et compo
77  vpTemplateTrackerPointSuppMIInv **ptTemplateSuppPyr; //pour inverse et compo
78  #endif
79 
84 
86 
96 
97  double gain;
100  bool blur;
101  bool useBrent;
102  unsigned int nbIterBrent;
103  unsigned int taillef;
104  double *fgG;
105  double *fgdG;
106  double ratioPixelIn;
107  int mod_i;
108  int mod_j;//variable de sampling de zone de reference
109  unsigned int nbParam ;
110  double lambdaDep ;
111  unsigned int iterationMax ;
112  //pour BFGS
113  unsigned int iterationGlobale;
114  //diverge is set to true if there is no more point in the tracked area
115  bool diverge;
116  unsigned int nbIteration;
119 
121  //Parametre de deplacement
124 
125  //temporary values for warping
128  //temporary derivative matrix
130 
134  vpTemplateTrackerZone zoneRef_; // Reference zone
135 
136  public:
138  virtual ~vpTemplateTracker();
139 
140  void display(const vpImage<unsigned char> &I, const vpColor& col = vpColor::green, const unsigned int thickness=3);
141  void display(const vpImage<vpRGBa> &I, const vpColor& col = vpColor::green, const unsigned int thickness=3);
142 
143  bool getDiverge() const {return diverge;}
144  vpColVector getdp(){ return dp; }
145  vpColVector getG() const { return G; }
146  vpMatrix getH() const { return H; }
147  unsigned int getNbParam() const { return nbParam ; }
148  unsigned int getNbIteration() const { return nbIteration; }
149  vpColVector getp() const { return p;}
150  double getRatioPixelIn() const {return ratioPixelIn;}
151 
156  vpTemplateTrackerWarp *getWarp() const {return Warp;}
157 
161  vpTemplateTrackerZone getZoneRef() const { return zoneRef_; }
162 
163  void initClick(const vpImage<unsigned char> &I, bool delaunay=false);
164  void initFromPoints(const vpImage<unsigned char> &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false);
165  void initFromZone(const vpImage<unsigned char> &I, const vpTemplateTrackerZone& zone);
166 
167  void resetTracker();
168 
169  void setBlur(bool b){blur = b;}
170  void setCostFunctionVerification(bool b){costFunctionVerification = b;}
171  void setGain(double g){gain=g;}
172  void setGaussianFilterSize(unsigned int new_taill);
173  void setHDes(vpMatrix &tH){ Hdesire=tH; vpMatrix::computeHLM(Hdesire,lambdaDep,HLMdesire); HLMdesireInverse = HLMdesire.inverseByLU();}
178  void setIterationMax(const unsigned int &n) { iterationMax = n ; }
183  void setLambda(double l) { lambdaDep = l ; }
184  void setNbIterBrent(const unsigned int &b){nbIterBrent=b;}
185  void setp(const vpColVector &tp){ p=tp; diverge=false; iterationGlobale=0; }
193  void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1) {
194  nbLvlPyr = nlevels;
195  l0Pyr = level_to_stop;
196  if(l0Pyr >= nlevels){
197  std::cout << "Warning: level_to_stop: " << level_to_stop << " higher than level_to_start: " << nlevels-1 << " (nlevels-1)" <<std::endl;
198  std::cout << "Level to stop put to: " << nlevels-1 << std::endl;
199  l0Pyr = nlevels-1;
200  }
201  }
210  void setSampling(int sample_i,int sample_j){mod_i=sample_i; mod_j=sample_j;}
211  void setThresholdGradient(double threshold){thresholdGradient=threshold;}
213  void setUseBrent(bool b){useBrent = b;}
214 
215  void track(const vpImage<unsigned char> &I);
216  void trackRobust(const vpImage<unsigned char> &I);
217 
218  protected:
219 
220  void computeOptimalBrentGain(const vpImage<unsigned char> &I,vpColVector &tp,double tMI,vpColVector &direction,double &alpha);
221  virtual double getCost(const vpImage<unsigned char> &I, vpColVector &tp) = 0;
223  void initCompInverse(const vpImage<unsigned char> &I);
224  virtual void initCompInversePyr(const vpImage<unsigned char> &I);
225  virtual void initHessienDesired(const vpImage<unsigned char> &I)=0;
226  virtual void initHessienDesiredPyr(const vpImage<unsigned char> &I);
227  virtual void initPyramidal(unsigned int nbLvl,unsigned int l0);
228  void initTracking(const vpImage<unsigned char>& I,vpTemplateTrackerZone &zone);
229  virtual void initTrackingPyr(const vpImage<unsigned char>& I,vpTemplateTrackerZone &zone);
230  virtual void trackNoPyr(const vpImage<unsigned char> &I) = 0;
231  virtual void trackPyr(const vpImage<unsigned char> &I);
232 };
233 #endif
234 
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
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:125
void setGain(double g)
void setIterationMax(const unsigned int &n)
void setUseBrent(bool b)
vpMatrix * HLMdesireInversePyr
vpImage< double > BI
static const vpColor green
Definition: vpColor.h:170
vpColVector getp() const
unsigned int templateSize
unsigned int iterationMax
vpTemplateTrackerZone * zoneTrackedPyr
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M)
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
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
void setLambda(double l)
vpMatrix inverseByLU() const
vpTemplateTrackerZone * zoneTracked
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:4320
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)