Visual Servoing Platform version 3.5.0
vpTemplateTracker.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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 http://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 * Template tracker.
33 *
34 * Authors:
35 * Amaury Dame
36 * Aurelien Yol
37 * Fabien Spindler
38 *
39 *****************************************************************************/
45#ifndef vpTemplateTracker_hh
46#define vpTemplateTracker_hh
47
48#include <math.h>
49
50#include <visp3/core/vpImageFilter.h>
51#include <visp3/tt/vpTemplateTrackerHeader.h>
52#include <visp3/tt/vpTemplateTrackerWarp.h>
53#include <visp3/tt/vpTemplateTrackerZone.h>
54
62class VISP_EXPORT vpTemplateTracker
63{
64protected:
65 // traitement pyramidal
66 unsigned int nbLvlPyr; // If = 1, disable pyramidal usage
67 unsigned int l0Pyr;
69 // For evolRMS computation
70 double evolRMS;
71 std::vector<double> x_pos;
72 std::vector<double> y_pos;
74
78 unsigned int templateSize;
79 unsigned int *templateSizePyr;
83 unsigned int templateSelectSize;
84
85#ifndef DOXYGEN_SHOULD_SKIP_THIS
86 vpTemplateTrackerPointSuppMIInv *ptTemplateSupp; // pour inverse et compo
87 vpTemplateTrackerPointSuppMIInv **ptTemplateSuppPyr; // pour inverse et compo
88#endif
89
94
96
106
107 double gain;
110 bool blur;
112 unsigned int nbIterBrent;
113 unsigned int taillef;
114 double *fgG;
115 double *fgdG;
117 int mod_i;
118 int mod_j; // variable de sampling de zone de reference
119 unsigned int nbParam;
120 double lambdaDep;
121 unsigned int iterationMax;
122 // pour BFGS
123 unsigned int iterationGlobale;
124 // diverge is set to true if there is no more point in the tracked area
126 unsigned int nbIteration;
129
131 // Parametre de deplacement
134
135 // temporary values for warping
138 // temporary derivative matrix
140
145
146public:
149 : nbLvlPyr(0), l0Pyr(0), pyrInitialised(false), ptTemplate(NULL), ptTemplatePyr(NULL), ptTemplateInit(false),
150 templateSize(0), templateSizePyr(NULL), ptTemplateSelect(NULL), ptTemplateSelectPyr(NULL),
151 ptTemplateSelectInit(false), templateSelectSize(0), ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL),
152 ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL), zoneTracked(NULL), zoneTrackedPyr(NULL), pyr_IDes(NULL), H(),
153 Hdesire(), HdesirePyr(NULL), HLM(), HLMdesire(), HLMdesirePyr(NULL), HLMdesireInverse(),
154 HLMdesireInversePyr(NULL), G(), gain(0), thresholdGradient(0), costFunctionVerification(false), blur(false),
155 useBrent(false), nbIterBrent(0), taillef(0), fgG(NULL), fgdG(NULL), ratioPixelIn(0), mod_i(0), mod_j(0),
156 nbParam(), lambdaDep(0), iterationMax(0), iterationGlobale(0), diverge(false), nbIteration(0),
157 useCompositionnal(false), useInverse(false), Warp(NULL), p(), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(),
158 zoneRef_()
159 {
160 }
162 virtual ~vpTemplateTracker();
163
164 void display(const vpImage<unsigned char> &I, const vpColor &col = vpColor::green, unsigned int thickness = 3);
165 void display(const vpImage<vpRGBa> &I, const vpColor &col = vpColor::green, unsigned int thickness = 3);
166
167 bool getDiverge() const { return diverge; }
168 vpColVector getdp() { return dp; }
169 vpColVector getG() const { return G; }
170 vpMatrix getH() const { return H; }
171 unsigned int getNbParam() const { return nbParam; }
172 unsigned int getNbIteration() const { return nbIteration; }
173 vpColVector getp() const { return p; }
174 double getRatioPixelIn() const { return ratioPixelIn; }
175
180 vpTemplateTrackerWarp *getWarp() const { return Warp; }
181
185 vpTemplateTrackerZone getZoneRef() const { return zoneRef_; }
186
187 void initClick(const vpImage<unsigned char> &I, bool delaunay = false);
188 void initFromPoints(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &v_ip, bool delaunay = false);
189 void initFromZone(const vpImage<unsigned char> &I, const vpTemplateTrackerZone &zone);
190
191 void resetTracker();
192
193 void setBlur(bool b) { blur = b; }
194 void setCostFunctionVerification(bool b) { costFunctionVerification = b; }
195 void setGain(double g) { gain = g; }
196 void setGaussianFilterSize(unsigned int new_taill);
198 {
199 Hdesire = tH;
200 vpMatrix::computeHLM(Hdesire, lambdaDep, HLMdesire);
201 HLMdesireInverse = HLMdesire.inverseByLU();
202 }
208 void setIterationMax(const unsigned int &n) { iterationMax = n; }
213 void setLambda(double l) { lambdaDep = l; }
214 void setNbIterBrent(const unsigned int &b) { nbIterBrent = b; }
215 void setp(const vpColVector &tp)
216 {
217 p = tp;
218 diverge = false;
219 iterationGlobale = 0;
220 }
230 void setPyramidal(unsigned int nlevels = 2, unsigned int level_to_stop = 1)
231 {
232 nbLvlPyr = nlevels;
233 l0Pyr = level_to_stop;
234 if (l0Pyr >= nlevels) {
235 std::cout << "Warning: level_to_stop: " << level_to_stop << " higher than level_to_start: " << nlevels - 1
236 << " (nlevels-1)" << std::endl;
237 std::cout << "Level to stop put to: " << nlevels - 1 << std::endl;
238 l0Pyr = nlevels - 1;
239 }
240 }
249 void setSampling(int sample_i, int sample_j)
250 {
251 mod_i = sample_i;
252 mod_j = sample_j;
253 }
254 void setThresholdGradient(double threshold) { thresholdGradient = threshold; }
264 void setThresholdResidualDifference(double threshold) { evolRMS_eps = threshold; }
265
267 void setUseBrent(bool b) { useBrent = b; }
268
269 void track(const vpImage<unsigned char> &I);
270 void trackRobust(const vpImage<unsigned char> &I);
271
272#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
282 vp_deprecated void setThresholdRMS(double threshold) { (void)threshold; }
284#endif
285
286protected:
287 void computeEvalRMS(const vpColVector &p);
288 void computeOptimalBrentGain(const vpImage<unsigned char> &I, vpColVector &tp, double tMI, vpColVector &direction,
289 double &alpha);
290 virtual double getCost(const vpImage<unsigned char> &I, const vpColVector &tp) = 0;
292 virtual void initHessienDesired(const vpImage<unsigned char> &I) = 0;
293 virtual void initHessienDesiredPyr(const vpImage<unsigned char> &I);
294 void initPosEvalRMS(const vpColVector &p);
295 virtual void initPyramidal(unsigned int nbLvl, unsigned int l0);
296 void initTracking(const vpImage<unsigned char> &I, vpTemplateTrackerZone &zone);
297 virtual void initTrackingPyr(const vpImage<unsigned char> &I, vpTemplateTrackerZone &zone);
298 virtual void trackNoPyr(const vpImage<unsigned char> &I) = 0;
299 virtual void trackPyr(const vpImage<unsigned char> &I);
300};
301#endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
static const vpColor green
Definition: vpColor.h:220
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, bool convolve=false)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
vpMatrix inverseByLU() const
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
Definition: vpMatrix.cpp:6683
vpColVector getG() const
vpImage< double > dIx
unsigned int nbIterBrent
void setThresholdGradient(double threshold)
unsigned int getNbIteration() const
void setCostFunctionVerification(bool b)
void setThresholdResidualDifference(double threshold)
vpImage< double > dIy
vpTemplateTracker()
Default constructor.
unsigned int templateSelectSize
vpTemplateTrackerPoint ** ptTemplatePyr
void setUseBrent(bool b)
unsigned int nbLvlPyr
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
unsigned int * templateSizePyr
void setIterationMax(const unsigned int &n)
vpTemplateTrackerZone * zoneTrackedPyr
vpTemplateTrackerZone zoneRef_
void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1)
vpImage< unsigned char > * pyr_IDes
std::vector< double > y_pos
unsigned int getNbParam() const
vpMatrix * HLMdesireInversePyr
vpMatrix getH() const
std::vector< double > x_pos
unsigned int iterationMax
virtual double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)=0
vpColVector getp() const
vpTemplateTrackerPointCompo ** ptTemplateCompoPyr
void getGaussianBluredImage(const vpImage< unsigned char > &I)
void setp(const vpColVector &tp)
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
unsigned int nbIteration
vpTemplateTrackerPoint * ptTemplate
void setNbIterBrent(const unsigned int &b)
vp_deprecated void setThresholdRMS(double threshold)
void setLambda(double l)
vpTemplateTrackerWarp * Warp
vpTemplateTrackerZone getZoneRef() const
double getRatioPixelIn() const
unsigned int iterationGlobale
bool getDiverge() const
void setSampling(int sample_i, int sample_j)
vpImage< double > BI
vpTemplateTrackerWarp * getWarp() const
void setGain(double g)
void setHDes(vpMatrix &tH)
unsigned int templateSize
vpTemplateTrackerPointCompo * ptTemplateCompo
vpTemplateTrackerZone * zoneTracked