Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpTemplateTrackerZNCC.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/tt/vpTemplateTrackerZNCC.h>
38
39
BEGIN_VISP_NAMESPACE
40
vpTemplateTrackerZNCC::vpTemplateTrackerZNCC
(
vpTemplateTrackerWarp
*warp) :
vpTemplateTracker
(warp),
DI
(),
temp
()
41
{
42
dW
.resize(2,
nbParam
);
43
G
.resize(
nbParam
);
44
H
.resize(
nbParam
,
nbParam
);
45
HLM
.resize(
nbParam
,
nbParam
);
46
47
temp
.resize(
nbParam
);
48
49
X1
.resize(2);
50
X2
.resize(2);
51
DI
.resize(2);
52
}
53
54
double
vpTemplateTrackerZNCC::getCost
(
const
vpImage<unsigned char>
&I,
const
vpColVector
&tp)
55
{
56
double
IW, Tij;
57
int
i, j;
58
double
i2, j2;
59
int
Nbpoint = 0;
60
61
Warp
->computeCoeff(tp);
62
63
double
moyTij = 0;
64
double
moyIW = 0;
65
for
(
unsigned
int
point = 0; point <
templateSize
; point++) {
66
i =
ptTemplate
[point].y;
67
j =
ptTemplate
[point].x;
68
X1
[0] = j;
69
X1
[1] = i;
70
Warp
->computeDenom(
X1
, tp);
71
Warp
->warpX(
X1
,
X2
, tp);
72
73
j2 =
X2
[0];
74
i2 =
X2
[1];
75
if
((j2 < I.getWidth() - 1) && (i2 < I.getHeight() - 1) && (i2 > 0) && (j2 > 0)) {
76
Tij =
ptTemplate
[point].val;
77
if
(!
blur
)
78
IW = I.getValue(i2, j2);
79
else
80
IW =
BI
.getValue(i2, j2);
81
moyTij += Tij;
82
moyIW += IW;
83
Nbpoint++;
84
}
85
}
86
ratioPixelIn
=
static_cast<
double
>
(Nbpoint) /
static_cast<
double
>
(
templateSize
);
87
if
(!Nbpoint) {
88
throw
(
vpException
(
vpException::divideByZeroError
,
"Cannot get cost: size = 0"
));
89
}
90
91
moyTij = moyTij / Nbpoint;
92
moyIW = moyIW / Nbpoint;
93
94
double
nom = 0;
95
double
var1 = 0, var2 = 0;
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
Warp
->computeDenom(
X1
, tp);
102
Warp
->warpX(
X1
,
X2
, tp);
103
104
j2 =
X2
[0];
105
i2 =
X2
[1];
106
if
((j2 < I.getWidth() - 1) && (i2 < I.getHeight() - 1) && (i2 > 0) && (j2 > 0)) {
107
Tij =
ptTemplate
[point].val;
108
if
(!
blur
)
109
IW = I.getValue(i2, j2);
110
else
111
IW =
BI
.getValue(i2, j2);
112
nom += (Tij - moyTij) * (IW - moyIW);
113
var1 += (IW - moyIW) * (IW - moyIW);
114
var2 += (Tij - moyTij) * (Tij - moyTij);
115
116
Nbpoint++;
117
}
118
}
119
return
-nom / sqrt(var1 * var2);
120
}
121
END_VISP_NAMESPACE
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::divideByZeroError
@ divideByZeroError
Division by zero.
Definition
vpException.h:70
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpTemplateTrackerWarp
Definition
vpTemplateTrackerWarp.h:65
vpTemplateTrackerZNCC::DI
vpRowVector DI
Definition
vpTemplateTrackerZNCC.h:74
vpTemplateTrackerZNCC::temp
vpRowVector temp
Definition
vpTemplateTrackerZNCC.h:75
vpTemplateTrackerZNCC::vpTemplateTrackerZNCC
VP_EXPLICIT vpTemplateTrackerZNCC(vpTemplateTrackerWarp *warp)
Definition
vpTemplateTrackerZNCC.cpp:40
vpTemplateTrackerZNCC::getCost
double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)
Definition
vpTemplateTrackerZNCC.cpp:54
vpTemplateTracker::nbParam
unsigned int nbParam
Definition
vpTemplateTracker.h:125
vpTemplateTracker::vpTemplateTracker
vpTemplateTracker()
Default constructor.
Definition
vpTemplateTracker.h:154
vpTemplateTracker::G
vpColVector G
Definition
vpTemplateTracker.h:111
vpTemplateTracker::H
vpMatrix H
Definition
vpTemplateTracker.h:103
vpTemplateTracker::X2
vpColVector X2
Definition
vpTemplateTracker.h:143
vpTemplateTracker::ratioPixelIn
double ratioPixelIn
Definition
vpTemplateTracker.h:122
vpTemplateTracker::ptTemplate
vpTemplateTrackerPoint * ptTemplate
Definition
vpTemplateTracker.h:81
vpTemplateTracker::dW
vpMatrix dW
Definition
vpTemplateTracker.h:145
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
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
tracker
tt
src
zncc
vpTemplateTrackerZNCC.cpp
Generated by
1.17.0