Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpTemplateTracker.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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 * Template tracker.
32 *
33 * Authors:
34 * Amaury Dame
35 * Aurelien Yol
36 */
41
42#ifndef vpTemplateTracker_hh
43#define vpTemplateTracker_hh
44
45#include <math.h>
46
47#include <visp3/core/vpConfig.h>
48#include <visp3/core/vpImageFilter.h>
49#include <visp3/tt/vpTemplateTrackerHeader.h>
50#include <visp3/tt/vpTemplateTrackerWarp.h>
51#include <visp3/tt/vpTemplateTrackerZone.h>
52
68class VISP_EXPORT vpTemplateTracker
69{
70protected:
71 // traitement pyramidal
72 unsigned int nbLvlPyr; // If = 1, disable pyramidal usage
73 unsigned int l0Pyr;
75 // For evolRMS computation
76 double evolRMS;
77 std::vector<double> x_pos;
78 std::vector<double> y_pos;
80
84 unsigned int templateSize;
85 unsigned int *templateSizePyr;
89 unsigned int templateSelectSize;
90
91#ifndef DOXYGEN_SHOULD_SKIP_THIS
92 vpTemplateTrackerPointSuppMIInv *ptTemplateSupp; // pour inverse et compo
93 vpTemplateTrackerPointSuppMIInv **ptTemplateSuppPyr; // pour inverse et compo
94#endif
95
100
102
112
113 double gain;
116 bool blur;
118 unsigned int nbIterBrent;
119 unsigned int taillef;
120 double *fgG;
121 double *fgdG;
123 int mod_i;
124 int mod_j; // variable de sampling de zone de reference
125 unsigned int nbParam;
126 double lambdaDep;
127 unsigned int iterationMax;
128 // pour BFGS
129 unsigned int iterationGlobale;
130 // diverge is set to true if there is no more point in the tracked area
132 unsigned int nbIteration;
135
137 // Parametre de deplacement
140
141 // temporary values for warping
144 // temporary derivative matrix
146
151
152public:
155 : nbLvlPyr(0), l0Pyr(0), pyrInitialised(false), ptTemplate(nullptr), ptTemplatePyr(nullptr), ptTemplateInit(false),
156 templateSize(0), templateSizePyr(nullptr), ptTemplateSelect(nullptr), ptTemplateSelectPyr(nullptr),
157 ptTemplateSelectInit(false), templateSelectSize(0), ptTemplateSupp(nullptr), ptTemplateSuppPyr(nullptr),
158 ptTemplateCompo(nullptr), ptTemplateCompoPyr(nullptr), zoneTracked(nullptr), zoneTrackedPyr(nullptr), pyr_IDes(nullptr), H(),
159 Hdesire(), HdesirePyr(nullptr), HLM(), HLMdesire(), HLMdesirePyr(nullptr), HLMdesireInverse(),
160 HLMdesireInversePyr(nullptr), G(), gain(0), thresholdGradient(0), costFunctionVerification(false), blur(false),
161 useBrent(false), nbIterBrent(0), taillef(0), fgG(nullptr), fgdG(nullptr), ratioPixelIn(0), mod_i(0), mod_j(0),
163 useCompositionnal(false), useInverse(false), Warp(nullptr), p(), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(),
164 zoneRef_()
165 { }
166 VP_EXPLICIT vpTemplateTracker(vpTemplateTrackerWarp *_warp);
167 virtual ~vpTemplateTracker();
168
169 void display(const vpImage<unsigned char> &I, const vpColor &col = vpColor::green, unsigned int thickness = 3);
170 void display(const vpImage<vpRGBa> &I, const vpColor &col = vpColor::green, unsigned int thickness = 3);
171
172 bool getDiverge() const { return diverge; }
173 vpColVector getdp() { return dp; }
174 vpColVector getG() const { return G; }
175 vpMatrix getH() const { return H; }
176 unsigned int getNbParam() const { return nbParam; }
177 unsigned int getNbIteration() const { return nbIteration; }
178 vpColVector getp() const { return p; }
179 double getRatioPixelIn() const { return ratioPixelIn; }
180
185 vpTemplateTrackerWarp *getWarp() const { return Warp; }
186
191
192 void initClick(const vpImage<unsigned char> &I, bool delaunay = false);
193 void initFromPoints(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &v_ip, bool delaunay = false);
194 void initFromZone(const vpImage<unsigned char> &I, const vpTemplateTrackerZone &zone);
195
196 void resetTracker();
197
198 void setBlur(bool b) { blur = b; }
200 void setGain(double g) { gain = g; }
201 void setGaussianFilterSize(unsigned int new_taill);
203 {
204 Hdesire = tH;
206 HLMdesireInverse = HLMdesire.inverseByLU();
207 }
208
213 void setIterationMax(const unsigned int &n) { iterationMax = n; }
218 void setLambda(double l) { lambdaDep = l; }
219 void setNbIterBrent(const unsigned int &b) { nbIterBrent = b; }
220 void setp(const vpColVector &tp)
221 {
222 p = tp;
223 diverge = false;
225 }
226
235 void setPyramidal(unsigned int nlevels = 2, unsigned int level_to_stop = 1)
236 {
237 nbLvlPyr = nlevels;
238 l0Pyr = level_to_stop;
239 if (l0Pyr >= nlevels) {
240 std::cout << "Warning: level_to_stop: " << level_to_stop << " higher than level_to_start: " << nlevels - 1
241 << " (nlevels-1)" << std::endl;
242 std::cout << "Level to stop put to: " << nlevels - 1 << std::endl;
243 l0Pyr = nlevels - 1;
244 }
245 }
246
254 void setSampling(int sample_i, int sample_j)
255 {
256 mod_i = sample_i;
257 mod_j = sample_j;
258 }
259 void setThresholdGradient(double threshold) { thresholdGradient = threshold; }
269 void setThresholdResidualDifference(double threshold) { evolRMS_eps = threshold; }
270
272 void setUseBrent(bool b) { useBrent = b; }
273
274 void track(const vpImage<unsigned char> &I);
275 void trackRobust(const vpImage<unsigned char> &I);
276
277#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
282
287 VP_DEPRECATED void setThresholdRMS(double threshold) { (void)threshold; }
289#endif
290
291protected:
292 void computeEvalRMS(const vpColVector &p);
293 void computeOptimalBrentGain(const vpImage<unsigned char> &I, vpColVector &tp, double tMI, vpColVector &direction,
294 double &alpha);
295 virtual double getCost(const vpImage<unsigned char> &I, const vpColVector &tp) = 0;
297 virtual void initHessienDesired(const vpImage<unsigned char> &I) = 0;
298 virtual void initHessienDesiredPyr(const vpImage<unsigned char> &I);
299 void initPosEvalRMS(const vpColVector &p);
300 virtual void initPyramidal(unsigned int nbLvl, unsigned int l0);
303 virtual void trackNoPyr(const vpImage<unsigned char> &I) = 0;
304 virtual void trackPyr(const vpImage<unsigned char> &I);
305};
306END_VISP_NAMESPACE
307#endif
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor green
Definition vpColor.h:201
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
vpColVector getG() const
vpImage< double > dIx
void initTracking(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
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
virtual void initHessienDesiredPyr(const vpImage< unsigned char > &I)
vpTemplateTrackerPoint ** ptTemplatePyr
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
VP_DEPRECATED void setThresholdRMS(double threshold)
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
virtual void trackPyr(const vpImage< unsigned char > &I)
void getGaussianBluredImage(const vpImage< unsigned char > &I)
void initPosEvalRMS(const vpColVector &p)
void setp(const vpColVector &tp)
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
vpTemplateTrackerPoint * ptTemplate
void setNbIterBrent(const unsigned int &b)
virtual void initTrackingPyr(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
virtual void initPyramidal(unsigned int nbLvl, unsigned int l0)
void setLambda(double l)
vpTemplateTrackerWarp * Warp
vpTemplateTrackerZone getZoneRef() const
double getRatioPixelIn() const
unsigned int iterationGlobale
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