Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpTemplateTrackerSSD.cpp
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 */
37
38#include <visp3/tt/vpTemplateTrackerSSD.h>
39
42{
43 dW.resize(2, nbParam);
44 G.resize(nbParam);
45 H.resize(nbParam, nbParam);
46 HLM.resize(nbParam, nbParam);
47
48 temp.resize(nbParam);
49
50 X1.resize(2);
51 X2.resize(2);
52 DI.resize(2);
53}
54
56{
57 double erreur = 0;
58 double IW;
59 int Nbpoint = 0;
60
61 Warp->computeCoeff(tp);
62 for (unsigned int point = 0; point < templateSize; point++) {
63 int i = ptTemplate[point].y;
64 int j = ptTemplate[point].x;
65 X1[0] = j;
66 X1[1] = i;
67 Warp->computeDenom(X1, tp);
68 Warp->warpX(X1, X2, tp);
69
70 double j2 = X2[0];
71 double i2 = X2[1];
72 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.getHeight() - 1) && (j2 < I.getWidth() - 1)) {
73 double Tij = ptTemplate[point].val;
74 if (!blur)
75 IW = I.getValue(i2, j2);
76 else
77 IW = BI.getValue(i2, j2);
78 erreur += (Tij - IW) * (Tij - IW);
79 Nbpoint++;
80 }
81 }
82 ratioPixelIn = static_cast<double>(Nbpoint) / static_cast<double>(templateSize);
83
84 if (Nbpoint == 0)
85 return 10e10;
86 return erreur / Nbpoint;
87}
88
90{
91 double erreur = 0;
92 double IW;
93 unsigned int Nbpoint = 0;
94
95 if (pyrInitialised) {
98 }
99
100 Warp->computeCoeff(tp);
101 for (unsigned int point = 0; point < templateSize; point++) {
102 int i = ptTemplate[point].y;
103 int j = ptTemplate[point].x;
104 X1[0] = j;
105 X1[1] = i;
106 Warp->computeDenom(X1, tp);
107 Warp->warpX(X1, X2, tp);
108
109 double j2 = X2[0];
110 double i2 = X2[1];
111 if ((j2 < I.getWidth() - 1) && (i2 < I.getHeight() - 1) && (i2 > 0) && (j2 > 0)) {
112 double Tij = ptTemplate[point].val;
113 IW = I.getValue(i2, j2);
114 erreur += (Tij - IW) * (Tij - IW);
115 Nbpoint++;
116 }
117 }
118 if (Nbpoint == 0)
119 return 10e10;
120 return erreur / Nbpoint;
121}
122END_VISP_NAMESPACE
Implementation of column vector and the associated operations.
Definition of the vpImage class member functions.
Definition vpImage.h:131
double getSSD(const vpImage< unsigned char > &I, const vpColVector &tp)
double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)
VP_EXPLICIT vpTemplateTrackerSSD(vpTemplateTrackerWarp *warp)
vpTemplateTracker()
Default constructor.
vpTemplateTrackerPoint ** ptTemplatePyr
unsigned int * templateSizePyr
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerWarp * Warp
vpImage< double > BI
unsigned int templateSize