Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpFeatureLuminance.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 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
* Luminance feature.
32
*/
33
40
41
#include <visp3/core/vpDebug.h>
42
#include <visp3/core/vpDisplay.h>
43
#include <visp3/core/vpException.h>
44
#include <visp3/core/vpHomogeneousMatrix.h>
45
#include <visp3/core/vpImageConvert.h>
46
#include <visp3/core/vpImageFilter.h>
47
#include <visp3/core/vpMatrix.h>
48
#include <visp3/core/vpPixelMeterConversion.h>
49
50
#include <visp3/visual_features/vpFeatureLuminance.h>
51
52
BEGIN_VISP_NAMESPACE
53
54
const
int
vpFeatureLuminance::DEFAULT_BORDER
= 10;
55
59
void
vpFeatureLuminance::init
()
60
{
61
if
(
flags
==
nullptr
)
62
flags
=
new
bool
[
nbParameters
];
63
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
64
flags
[i] =
false
;
65
66
// default value Z (1 meters)
67
Z
= 1;
68
69
firstTimeIn
= 0;
70
71
nbr
=
nbc
= 0;
72
}
73
74
void
vpFeatureLuminance::init
(
unsigned
int
nbr_,
unsigned
int
nbc_,
double
Z_)
75
{
76
init
();
77
78
nbr
= nbr_;
79
nbc
= nbc_;
80
81
if
((
nbr
< 2 *
bord
) || (
nbc
< 2 *
bord
)) {
82
throw
vpException
(
vpException::dimensionError
,
"border is too important compared to number of row or column."
);
83
}
84
85
// number of feature = nb column x nb lines in the images
86
dim_s
= (
nbr
- 2 *
bord
) * (
nbc
- 2 *
bord
);
87
88
s
.resize(
dim_s
);
89
90
if
(
pixInfo
!=
nullptr
)
91
delete
[]
pixInfo
;
92
93
pixInfo
=
new
vpLuminance[
dim_s
];
94
95
Z
= Z_;
96
}
97
101
vpFeatureLuminance::vpFeatureLuminance
() :
Z
(1),
nbr
(0),
nbc
(0),
bord
(
DEFAULT_BORDER
),
pixInfo
(nullptr),
firstTimeIn
(0),
cam
()
102
{
103
nbParameters
= 1;
104
dim_s
= 0;
105
if
(
flags
!=
nullptr
) {
106
delete
[]
flags
;
107
}
108
flags
=
nullptr
;
109
110
init
();
111
}
112
116
vpFeatureLuminance::vpFeatureLuminance
(
const
vpFeatureLuminance
&f)
117
:
vpBasicFeature
(f),
Z
(1),
nbr
(0),
nbc
(0),
bord
(
DEFAULT_BORDER
),
pixInfo
(nullptr),
firstTimeIn
(0),
cam
()
118
{
119
*
this
= f;
120
}
121
125
vpFeatureLuminance
&
vpFeatureLuminance::operator=
(
const
vpFeatureLuminance
&f)
126
{
127
Z
= f.
Z
;
128
nbr
= f.
nbr
;
129
nbc
= f.
nbc
;
130
bord
= f.
bord
;
131
firstTimeIn
= f.
firstTimeIn
;
132
cam
= f.
cam
;
133
dim_s
= f.
dim_s
;
134
if
(
pixInfo
)
135
delete
[]
pixInfo
;
136
pixInfo
=
new
vpLuminance[
dim_s
];
137
for
(
unsigned
int
i = 0; i <
dim_s
; i++)
138
pixInfo
[i] = f.
pixInfo
[i];
139
s
.resize(
dim_s
);
140
return
(*
this
);
141
}
142
146
vpFeatureLuminance::~vpFeatureLuminance
()
147
{
148
if
(
pixInfo
!=
nullptr
) {
149
delete
[]
pixInfo
;
150
}
151
}
152
159
void
vpFeatureLuminance::set_Z
(
double
Z_)
160
{
161
this->
Z
= Z_;
162
flags
[0] =
true
;
163
}
164
171
double
vpFeatureLuminance::get_Z
()
const
{
return
Z
; }
172
unsigned
int
vpFeatureLuminance::getBorder
()
const
{
return
bord
; }
173
174
void
vpFeatureLuminance::setCameraParameters
(
const
vpCameraParameters
&_cam) {
cam
= _cam; }
175
180
181
vpFeatureLuminance
&
vpFeatureLuminance::buildFrom
(
vpImage<unsigned char>
&I)
182
{
183
unsigned
int
l = 0;
184
double
Ix, Iy;
185
186
double
px =
cam
.get_px();
187
double
py =
cam
.get_py();
188
189
if
(
firstTimeIn
== 0) {
190
firstTimeIn
= 1;
191
l = 0;
192
for
(
unsigned
int
i =
bord
; i <
nbr
-
bord
; i++) {
193
for
(
unsigned
int
j =
bord
; j <
nbc
-
bord
; j++) {
194
195
double
x = 0, y = 0;
196
vpPixelMeterConversion::convertPoint
(
cam
, j, i, x, y);
197
198
pixInfo
[l].x = x;
199
pixInfo
[l].y = y;
200
pixInfo
[l].Z =
Z
;
201
202
++l;
203
}
204
}
205
}
206
207
l = 0;
208
209
for
(
unsigned
int
i =
bord
; i < (
nbr
-
bord
); ++i) {
210
for
(
unsigned
int
j =
bord
; j < (
nbc
-
bord
); ++j) {
211
Ix = px *
vpImageFilter::derivativeFilterX
(I, i, j);
212
Iy = py *
vpImageFilter::derivativeFilterY
(I, i, j);
213
214
// Calcul de Z
215
pixInfo
[l].I = I[i][j];
216
s
[l] = I[i][j];
217
pixInfo
[l].Ix = Ix;
218
pixInfo
[l].Iy = Iy;
219
220
++l;
221
}
222
}
223
return
*
this
;
224
}
225
230
void
vpFeatureLuminance::interaction
(
vpMatrix
&L)
231
{
232
L.
resize
(
dim_s
, 6);
233
234
for
(
unsigned
int
m = 0; m < L.getRows(); m++) {
235
double
Ix =
pixInfo
[m].Ix;
236
double
Iy =
pixInfo
[m].Iy;
237
238
double
x =
pixInfo
[m].x;
239
double
y =
pixInfo
[m].y;
240
double
Zinv = 1 /
pixInfo
[m].Z;
241
242
{
243
L[m][0] = Ix * Zinv;
244
L[m][1] = Iy * Zinv;
245
L[m][2] = -(x * Ix + y * Iy) * Zinv;
246
L[m][3] = -Ix * x * y - (1 + y * y) * Iy;
247
L[m][4] = (1 + x * x) * Ix + Iy * x * y;
248
L[m][5] = Iy * x - Ix * y;
249
}
250
}
251
}
252
257
vpMatrix
vpFeatureLuminance::interaction
(
const
unsigned
int
/* select */
)
258
{
259
/* static */
vpMatrix
L;
// warning C4640: 'L' : construction of local
260
// static object is not thread-safe
261
interaction
(L);
262
return
L;
263
}
264
272
void
vpFeatureLuminance::error
(
const
vpBasicFeature
&s_star,
vpColVector
&e)
273
{
274
e.resize(
dim_s
);
275
276
for
(
unsigned
int
i = 0; i <
dim_s
; i++) {
277
e[i] =
s
[i] - s_star[i];
278
}
279
}
280
287
vpColVector
vpFeatureLuminance::error
(
const
vpBasicFeature
&s_star,
const
unsigned
int
select)
288
{
289
(void)select;
290
/* static */
vpColVector
e;
// warning C4640: 'e' : construction of local
291
// static object is not thread-safe
292
293
error
(s_star, e);
294
295
return
e;
296
}
297
303
void
vpFeatureLuminance::print
(
const
unsigned
int
/* select */
)
const
304
{
305
static
int
firsttime = 0;
306
307
if
(firsttime == 0) {
308
firsttime = 1;
309
vpERROR_TRACE
(
"not implemented"
);
310
// Do not throw and error since it is not subject
311
// to produce a failure
312
}
313
}
314
320
void
vpFeatureLuminance::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<unsigned char>
&
/* I */
,
321
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
322
{
323
static
int
firsttime = 0;
324
325
if
(firsttime == 0) {
326
firsttime = 1;
327
vpERROR_TRACE
(
"not implemented"
);
328
// Do not throw and error since it is not subject
329
// to produce a failure
330
}
331
}
332
338
void
vpFeatureLuminance::display
(
const
vpCameraParameters
&
/* cam */
,
const
vpImage<vpRGBa>
&
/* I */
,
339
const
vpColor
&
/* color */
,
unsigned
int
/* thickness */
)
const
340
{
341
static
int
firsttime = 0;
342
343
if
(firsttime == 0) {
344
firsttime = 1;
345
vpERROR_TRACE
(
"not implemented"
);
346
// Do not throw and error since it is not subject
347
// to produce a failure
348
}
349
}
350
361
vpFeatureLuminance
*
vpFeatureLuminance::duplicate
()
const
362
{
363
vpFeatureLuminance
*feature =
new
vpFeatureLuminance
;
364
return
feature;
365
}
366
367
END_VISP_NAMESPACE
vpArray2D::resize
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition
vpArray2D.h:448
vpBasicFeature::flags
bool * flags
Definition
vpBasicFeature.h:96
vpBasicFeature::s
vpColVector s
State of the visual feature.
Definition
vpBasicFeature.h:90
vpBasicFeature::nbParameters
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
Definition
vpBasicFeature.h:98
vpBasicFeature::dim_s
unsigned int dim_s
Dimension of the visual feature.
Definition
vpBasicFeature.h:92
vpBasicFeature::vpBasicFeature
vpBasicFeature()
Definition
vpBasicFeature.cpp:59
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition
vpCameraParameters.h:311
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpColor
Class to define RGB colors available for display functionalities.
Definition
vpColor.h:157
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::dimensionError
@ dimensionError
Bad dimension.
Definition
vpException.h:71
vpFeatureLuminance::buildFrom
vpFeatureLuminance & buildFrom(vpImage< unsigned char > &I)
Definition
vpFeatureLuminance.cpp:181
vpFeatureLuminance::error
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeatureLuminance.cpp:287
vpFeatureLuminance::init
void init() VP_OVERRIDE
Definition
vpFeatureLuminance.cpp:59
vpFeatureLuminance::interaction
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Definition
vpFeatureLuminance.cpp:257
vpFeatureLuminance::nbr
unsigned int nbr
Number of rows.
Definition
vpFeatureLuminance.h:82
vpFeatureLuminance::DEFAULT_BORDER
static const int DEFAULT_BORDER
Definition
vpFeatureLuminance.h:128
vpFeatureLuminance::print
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
Definition
vpFeatureLuminance.cpp:303
vpFeatureLuminance::vpFeatureLuminance
vpFeatureLuminance()
Definition
vpFeatureLuminance.cpp:101
vpFeatureLuminance::setCameraParameters
void setCameraParameters(const vpCameraParameters &_cam)
Definition
vpFeatureLuminance.cpp:174
vpFeatureLuminance::cam
vpCameraParameters cam
Definition
vpFeatureLuminance.h:131
vpFeatureLuminance::get_Z
double get_Z() const
Definition
vpFeatureLuminance.cpp:171
vpFeatureLuminance::pixInfo
vpLuminance * pixInfo
Store the image (as a vector with intensity and gradient I, Ix, Iy).
Definition
vpFeatureLuminance.h:89
vpFeatureLuminance::duplicate
vpFeatureLuminance * duplicate() const VP_OVERRIDE
Definition
vpFeatureLuminance.cpp:361
vpFeatureLuminance::~vpFeatureLuminance
virtual ~vpFeatureLuminance() VP_OVERRIDE
Destructor.
Definition
vpFeatureLuminance.cpp:146
vpFeatureLuminance::getBorder
unsigned int getBorder() const
Definition
vpFeatureLuminance.cpp:172
vpFeatureLuminance::display
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition
vpFeatureLuminance.cpp:320
vpFeatureLuminance::set_Z
void set_Z(double Z)
Definition
vpFeatureLuminance.cpp:159
vpFeatureLuminance::firstTimeIn
int firstTimeIn
Definition
vpFeatureLuminance.h:90
vpFeatureLuminance::nbc
unsigned int nbc
Number of column.
Definition
vpFeatureLuminance.h:84
vpFeatureLuminance::Z
double Z
Definition
vpFeatureLuminance.h:79
vpFeatureLuminance::bord
unsigned int bord
Border size.
Definition
vpFeatureLuminance.h:86
vpFeatureLuminance::operator=
vpFeatureLuminance & operator=(const vpFeatureLuminance &f)
Definition
vpFeatureLuminance.cpp:125
vpImageFilter::derivativeFilterX
static double derivativeFilterX(const vpImage< ImageType > &I, unsigned int r, unsigned int c)
Definition
vpImageFilter.h:608
vpImageFilter::derivativeFilterY
static double derivativeFilterY(const vpImage< ImageType > &I, unsigned int r, unsigned int c)
Definition
vpImageFilter.h:622
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpMatrix
Implementation of a matrix and operations on matrices.
Definition
vpMatrix.h:175
vpPixelMeterConversion::convertPoint
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Definition
vpPixelMeterConversion.h:108
vpERROR_TRACE
#define vpERROR_TRACE
Definition
vpDebug.h:423
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
visual_features
src
visual-feature
vpFeatureLuminance.cpp
Generated by
1.17.0