Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpTemplateTrackerSSDForwardCompositional.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
#include <visp3/core/vpImageFilter.h>
38
#include <visp3/tt/vpTemplateTrackerSSDForwardCompositional.h>
39
40
BEGIN_VISP_NAMESPACE
41
vpTemplateTrackerSSDForwardCompositional::vpTemplateTrackerSSDForwardCompositional
(
vpTemplateTrackerWarp
*warp)
42
:
vpTemplateTrackerSSD
(warp),
compoInitialised
(false)
43
{ }
44
45
void
vpTemplateTrackerSSDForwardCompositional::initCompo
(
const
vpImage<unsigned char>
&
/*I*/
)
46
{
47
for
(
unsigned
int
point = 0; point <
templateSize
; point++) {
48
int
i =
ptTemplate
[point].y;
49
int
j =
ptTemplate
[point].x;
50
ptTemplate
[point].dW =
new
double
[2 *
nbParam
];
51
X1
[0] = j;
52
X1
[1] = i;
53
Warp
->computeDenom(
X1
,
p
);
54
Warp
->getdWdp0(i, j,
ptTemplate
[point].
dW
);
55
}
56
compoInitialised
=
true
;
57
}
58
59
void
vpTemplateTrackerSSDForwardCompositional::initHessienDesired
(
const
vpImage<unsigned char>
&I) {
initCompo
(I); }
60
61
void
vpTemplateTrackerSSDForwardCompositional::trackNoPyr
(
const
vpImage<unsigned char>
&I)
62
{
63
if
(!
compoInitialised
) {
64
std::cout <<
"Compositionnal tracking not initialised.\nUse initCompo() function."
<< std::endl;
65
}
66
67
if
(
blur
) {
68
vpImageFilter::filter
(I,
BI
,
fgG
,
taillef
);
69
}
70
vpImageFilter::getGradXGauss2D
(I,
dIx
,
fgG
,
fgdG
,
taillef
);
71
vpImageFilter::getGradYGauss2D
(I,
dIy
,
fgG
,
fgdG
,
taillef
);
72
73
dW
= 0;
74
75
double
lambda =
lambdaDep
;
76
double
IW, dIWx, dIWy;
77
double
Tij;
78
unsigned
int
iteration = 0;
79
int
i, j;
80
double
i2, j2;
81
double
alpha = 2.;
82
83
initPosEvalRMS
(
p
);
84
85
double
evolRMS_init = 0;
86
double
evolRMS_prec = 0;
87
double
evolRMS_delta;
88
double
*tempt =
new
double
[
nbParam
];
89
90
do
{
91
unsigned
int
Nbpoint = 0;
92
double
erreur = 0;
93
G
= 0;
94
H
= 0;
95
Warp
->computeCoeff(
p
);
96
for
(
unsigned
int
point = 0; point <
templateSize
; point++) {
97
i =
ptTemplate
[point].y;
98
j =
ptTemplate
[point].x;
99
X1
[0] = j;
100
X1
[1] = i;
101
102
Warp
->computeDenom(
X1
,
p
);
103
Warp
->warpX(
X1
,
X2
,
p
);
104
105
j2 =
X2
[0];
106
i2 =
X2
[1];
107
if
((i2 >= 0) && (j2 >= 0) && (i2 < I.getHeight() - 1) && (j2 < I.getWidth() - 1)) {
108
Tij =
ptTemplate
[point].val;
109
if
(!
blur
)
110
IW = I.getValue(i2, j2);
111
else
112
IW =
BI
.getValue(i2, j2);
113
dIWx =
dIx
.getValue(i2, j2);
114
dIWy =
dIy
.getValue(i2, j2);
115
Nbpoint++;
116
117
Warp
->dWarpCompo(
X1
,
X2
,
p
,
ptTemplate
[point].
dW
,
dW
);
118
119
for
(
unsigned
int
it = 0; it <
nbParam
; it++)
120
tempt[it] =
dW
[0][it] * dIWx +
dW
[1][it] * dIWy;
121
122
for
(
unsigned
int
it = 0; it <
nbParam
; it++)
123
for
(
unsigned
int
jt = 0; jt <
nbParam
; jt++)
124
H
[it][jt] += tempt[it] * tempt[jt];
125
126
double
er = (Tij - IW);
127
for
(
unsigned
int
it = 0; it <
nbParam
; it++)
128
G
[it] += er * tempt[it];
129
130
erreur += (er * er);
131
}
132
}
133
if
(Nbpoint == 0) {
134
delete
[] tempt;
135
throw
(
vpTrackingException
(
vpTrackingException::notEnoughPointError
,
"No points in the template"
));
136
}
137
138
vpMatrix::computeHLM
(
H
, lambda,
HLM
);
139
140
try
{
141
dp
=
HLM
.inverseByLU() *
G
;
142
}
143
catch
(
const
vpException
&e) {
144
delete
[] tempt;
145
throw
(e);
146
}
147
148
dp
=
gain
*
dp
;
149
if
(
useBrent
) {
150
alpha = 2.;
151
computeOptimalBrentGain
(I,
p
, erreur / Nbpoint,
dp
, alpha);
152
dp
= alpha *
dp
;
153
}
154
Warp
->pRondp(
p
,
dp
,
p
);
155
156
computeEvalRMS
(
p
);
157
158
if
(iteration == 0) {
159
evolRMS_init =
evolRMS
;
160
}
161
iteration++;
162
163
evolRMS_delta = std::fabs(
evolRMS
- evolRMS_prec);
164
evolRMS_prec =
evolRMS
;
165
166
}
while
((iteration <
iterationMax
) && (evolRMS_delta > std::fabs(evolRMS_init) *
evolRMS_eps
));
167
delete
[] tempt;
168
169
nbIteration
= iteration;
170
}
171
END_VISP_NAMESPACE
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpImageFilter::getGradXGauss2D
static void getGradXGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIx, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size, const vpImage< bool > *p_mask=nullptr)
Definition
vpImageFilter.h:2038
vpImageFilter::filter
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
Definition
vpImageFilter.h:715
vpImageFilter::getGradYGauss2D
static void getGradYGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIy, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size, const vpImage< bool > *p_mask=nullptr)
Definition
vpImageFilter.h:2189
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpMatrix::computeHLM
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
Definition
vpMatrix.cpp:1882
vpTemplateTrackerSSDForwardCompositional::vpTemplateTrackerSSDForwardCompositional
VP_EXPLICIT vpTemplateTrackerSSDForwardCompositional(vpTemplateTrackerWarp *warp)
Definition
vpTemplateTrackerSSDForwardCompositional.cpp:41
vpTemplateTrackerSSDForwardCompositional::initHessienDesired
void initHessienDesired(const vpImage< unsigned char > &I)
Definition
vpTemplateTrackerSSDForwardCompositional.cpp:59
vpTemplateTrackerSSDForwardCompositional::compoInitialised
bool compoInitialised
Definition
vpTemplateTrackerSSDForwardCompositional.h:64
vpTemplateTrackerSSDForwardCompositional::initCompo
void initCompo(const vpImage< unsigned char > &I)
Definition
vpTemplateTrackerSSDForwardCompositional.cpp:45
vpTemplateTrackerSSDForwardCompositional::trackNoPyr
void trackNoPyr(const vpImage< unsigned char > &I)
Definition
vpTemplateTrackerSSDForwardCompositional.cpp:61
vpTemplateTrackerSSD::vpTemplateTrackerSSD
VP_EXPLICIT vpTemplateTrackerSSD(vpTemplateTrackerWarp *warp)
Definition
vpTemplateTrackerSSD.cpp:41
vpTemplateTrackerWarp
Definition
vpTemplateTrackerWarp.h:65
vpTemplateTracker::nbParam
unsigned int nbParam
Definition
vpTemplateTracker.h:125
vpTemplateTracker::dIx
vpImage< double > dIx
Definition
vpTemplateTracker.h:148
vpTemplateTracker::useBrent
bool useBrent
Definition
vpTemplateTracker.h:117
vpTemplateTracker::dIy
vpImage< double > dIy
Definition
vpTemplateTracker.h:149
vpTemplateTracker::lambdaDep
double lambdaDep
Definition
vpTemplateTracker.h:126
vpTemplateTracker::computeEvalRMS
void computeEvalRMS(const vpColVector &p)
Definition
vpTemplateTracker.cpp:790
vpTemplateTracker::G
vpColVector G
Definition
vpTemplateTracker.h:111
vpTemplateTracker::evolRMS
double evolRMS
Definition
vpTemplateTracker.h:76
vpTemplateTracker::p
vpColVector p
Definition
vpTemplateTracker.h:138
vpTemplateTracker::computeOptimalBrentGain
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
Definition
vpTemplateTracker.cpp:371
vpTemplateTracker::H
vpMatrix H
Definition
vpTemplateTracker.h:103
vpTemplateTracker::evolRMS_eps
double evolRMS_eps
Definition
vpTemplateTracker.h:79
vpTemplateTracker::gain
double gain
Definition
vpTemplateTracker.h:113
vpTemplateTracker::X2
vpColVector X2
Definition
vpTemplateTracker.h:143
vpTemplateTracker::taillef
unsigned int taillef
Definition
vpTemplateTracker.h:119
vpTemplateTracker::fgdG
double * fgdG
Definition
vpTemplateTracker.h:121
vpTemplateTracker::iterationMax
unsigned int iterationMax
Definition
vpTemplateTracker.h:127
vpTemplateTracker::initPosEvalRMS
void initPosEvalRMS(const vpColVector &p)
Definition
vpTemplateTracker.cpp:823
vpTemplateTracker::nbIteration
unsigned int nbIteration
Definition
vpTemplateTracker.h:132
vpTemplateTracker::ptTemplate
vpTemplateTrackerPoint * ptTemplate
Definition
vpTemplateTracker.h:81
vpTemplateTracker::dW
vpMatrix dW
Definition
vpTemplateTracker.h:145
vpTemplateTracker::dp
vpColVector dp
Definition
vpTemplateTracker.h:139
vpTemplateTracker::fgG
double * fgG
Definition
vpTemplateTracker.h:120
vpTemplateTracker::Warp
vpTemplateTrackerWarp * Warp
Definition
vpTemplateTracker.h:136
vpTemplateTracker::blur
bool blur
Definition
vpTemplateTracker.h:116
vpTemplateTracker::BI
vpImage< double > BI
Definition
vpTemplateTracker.h:147
vpTemplateTracker::X1
vpColVector X1
Definition
vpTemplateTracker.h:142
vpTemplateTracker::HLM
vpMatrix HLM
Definition
vpTemplateTracker.h:106
vpTemplateTracker::templateSize
unsigned int templateSize
Definition
vpTemplateTracker.h:84
vpTrackingException
Error that can be emitted by the vpTracker class and its derivatives.
Definition
vpTrackingException.h:55
vpTrackingException::notEnoughPointError
@ notEnoughPointError
Not enough point to track.
Definition
vpTrackingException.h:65
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
tracker
tt
src
ssd
vpTemplateTrackerSSDForwardCompositional.cpp
Generated by
1.17.0