ViSP
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Functions
Variables
Enumerations
Enumerator
Friends
Groups
Pages
vpFeatureLuminance.cpp
1
2
3
#include <visp/vpMatrix.h>
4
#include <visp/vpHomogeneousMatrix.h>
5
#include <visp/vpDisplay.h>
6
#include <visp/vpPixelMeterConversion.h>
7
#include <visp/vpImageConvert.h>
8
#include <visp/vpImageFilter.h>
9
#include <visp/vpException.h>
10
11
#include <visp/vpFeatureLuminance.h>
12
13
30
void
31
vpFeatureLuminance::init
()
32
{
33
if
(
flags
== NULL)
34
flags
=
new
bool
[
nbParameters
];
35
for
(
unsigned
int
i = 0; i <
nbParameters
; i++)
flags
[i] =
false
;
36
37
//default value Z (1 meters)
38
Z
= 1;
39
40
firstTimeIn
=0 ;
41
42
}
43
44
45
void
46
vpFeatureLuminance::init
(
unsigned
int
_nbr,
unsigned
int
_nbc,
double
_Z)
47
{
48
init
() ;
49
50
nbr
= _nbr ;
51
nbc
= _nbc ;
52
53
if
((
nbr
< 2*
bord
) || (
nbc
< 2*
bord
)){
54
throw
vpException
(
vpException::dimensionError
,
"border is too important compared to number of row or column."
);
55
}
56
57
// number of feature = nb column x nb lines in the images
58
dim_s
= (
nbr
-2*
bord
)*(
nbc
-2*
bord
) ;
59
60
s
.
resize
(
dim_s
) ;
61
62
if
(
pixInfo
!= NULL)
63
delete
[]
pixInfo
;
64
65
pixInfo
=
new
vpLuminance
[
dim_s
] ;
66
67
Z
= _Z ;
68
}
69
73
vpFeatureLuminance::vpFeatureLuminance
() :
vpBasicFeature
()
74
{
75
nbParameters
= 1;
76
dim_s
= 0 ;
77
bord
= 10 ;
78
flags
= NULL;
79
pixInfo
= NULL;
80
81
init
() ;
82
}
83
87
vpFeatureLuminance::~vpFeatureLuminance
()
88
{
89
if
(
pixInfo
!= NULL)
delete
[]
pixInfo
;
90
if
(
flags
!= NULL)
delete
[]
flags
;
91
}
92
93
94
100
void
101
vpFeatureLuminance::set_Z
(
const
double
Z)
102
{
103
this->Z =
Z
;
104
flags
[0] =
true
;
105
}
106
107
113
double
114
vpFeatureLuminance::get_Z
()
const
115
{
116
return
Z
;
117
}
118
119
120
void
121
vpFeatureLuminance::setCameraParameters
(
vpCameraParameters
&_cam)
122
{
123
cam
= _cam ;
124
}
125
126
132
void
133
vpFeatureLuminance::buildFrom
(
vpImage<unsigned char>
&I)
134
{
135
unsigned
int
l = 0;
136
double
Ix,Iy ;
137
138
double
px =
cam
.
get_px
() ;
139
double
py =
cam
.
get_py
() ;
140
141
142
if
(
firstTimeIn
==0)
143
{
144
firstTimeIn
=1 ;
145
l =0 ;
146
for
(
unsigned
int
i=
bord
; i <
nbr
-
bord
; i++)
147
{
148
// cout << i << endl ;
149
for
(
unsigned
int
j = bord ; j <
nbc
-
bord
; j++)
150
{
double
x=0,y=0;
151
vpPixelMeterConversion::convertPoint
(
cam
,
152
j,i,
153
x,y) ;
154
155
pixInfo
[l].
x
= x;
156
pixInfo
[l].
y
= y;
157
158
pixInfo
[l].
Z
=
Z
;
159
160
l++;
161
}
162
}
163
}
164
165
l= 0 ;
166
for
(
unsigned
int
i=
bord
; i <
nbr
-
bord
; i++)
167
{
168
// cout << i << endl ;
169
for
(
unsigned
int
j = bord ; j <
nbc
-
bord
; j++)
170
{
171
// cout << dim_s <<" " <<l <<" " <<i << " " << j <<endl ;
172
Ix = px *
vpImageFilter::derivativeFilterX
(I,i,j) ;
173
Iy = py *
vpImageFilter::derivativeFilterY
(I,i,j) ;
174
175
// Calcul de Z
176
177
pixInfo
[l].
I
= I[i][j] ;
178
s
[l] = I[i][j] ;
179
pixInfo
[l].
Ix
= Ix;
180
pixInfo
[l].
Iy
= Iy;
181
182
l++;
183
}
184
}
185
186
}
187
188
189
190
196
void
197
vpFeatureLuminance::interaction
(
vpMatrix
&L)
198
{
199
double
x,y,Ix,Iy,Zinv;
200
201
L.
resize
(
dim_s
,6) ;
202
203
for
(
unsigned
int
m = 0; m< L.
getRows
(); m++)
204
{
205
Ix =
pixInfo
[m].
Ix
;
206
Iy =
pixInfo
[m].
Iy
;
207
208
x =
pixInfo
[m].
x
;
209
y =
pixInfo
[m].
y
;
210
Zinv = 1 /
pixInfo
[m].
Z
;
211
212
{
213
L[m][0] = Ix * Zinv;
214
L[m][1] = Iy * Zinv;
215
L[m][2] = -(x*Ix+y*Iy)*Zinv;
216
L[m][3] = -Ix*x*y-(1+y*y)*Iy;
217
L[m][4] = (1+x*x)*Ix + Iy*x*y;
218
L[m][5] = Iy*x-Ix*y;
219
}
220
}
221
}
222
227
vpMatrix
vpFeatureLuminance::interaction
(
const
unsigned
int
/* select */
)
228
{
229
/* static */
vpMatrix
L ;
// warning C4640: 'L' : construction of local static object is not thread-safe
230
interaction
(L) ;
231
return
L ;
232
}
233
234
242
void
243
vpFeatureLuminance::error
(
const
vpBasicFeature
&s_star,
244
vpColVector
&e)
245
{
246
e.
resize
(
dim_s
) ;
247
248
for
(
unsigned
int
i =0 ; i <
dim_s
; i++)
249
{
250
e[i] =
s
[i] - s_star[i] ;
251
}
252
}
253
254
255
263
vpColVector
264
vpFeatureLuminance::error
(
const
vpBasicFeature
&s_star,
265
const
unsigned
int
/* select */
)
266
{
267
/* static */
vpColVector
e ;
// warning C4640: 'e' : construction of local static object is not thread-safe
268
269
error
(s_star, e) ;
270
271
return
e ;
272
273
}
274
275
276
277
283
void
284
vpFeatureLuminance::print
(
const
unsigned
int
/* select */
)
const
285
{
286
static
int
firsttime =0 ;
287
288
if
(firsttime==0)
289
{
290
firsttime=1 ;
291
vpERROR_TRACE
(
"not implemented"
) ;
292
// Do not throw and error since it is not subject
293
// to produce a failure
294
}
295
}
296
297
298
304
void
305
vpFeatureLuminance::display
(
const
vpCameraParameters
&
/* cam */
,
306
const
vpImage<unsigned char>
&
/* I */
,
307
const
vpColor
&
/* color */
,
308
unsigned
int
/* thickness */
)
const
309
{
310
static
int
firsttime =0 ;
311
312
if
(firsttime==0)
313
{
314
firsttime=1 ;
315
vpERROR_TRACE
(
"not implemented"
) ;
316
// Do not throw and error since it is not subject
317
// to produce a failure
318
}
319
}
320
326
void
327
vpFeatureLuminance::display
(
const
vpCameraParameters
&
/* cam */
,
328
const
vpImage<vpRGBa>
&
/* I */
,
329
const
vpColor
&
/* color */
,
330
unsigned
int
/* thickness */
)
const
331
{
332
static
int
firsttime =0 ;
333
334
if
(firsttime==0)
335
{
336
firsttime=1 ;
337
vpERROR_TRACE
(
"not implemented"
) ;
338
// Do not throw and error since it is not subject
339
// to produce a failure
340
}
341
}
342
343
354
vpFeatureLuminance
*
vpFeatureLuminance::duplicate
()
const
355
{
356
vpFeatureLuminance
*feature =
new
vpFeatureLuminance
;
357
return
feature ;
358
}
359
360
361
/*
362
* Local variables:
363
* c-basic-offset: 2
364
* End:
365
*/
src
visual-feature
vpFeatureLuminance.cpp
Generated on Thu Oct 24 2013 14:47:38 for ViSP by
1.8.4