ViSP  2.9.0
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 
26 void
28 {
29  if (flags == NULL)
30  flags = new bool[nbParameters];
31  for (unsigned int i = 0; i < nbParameters; i++) flags[i] = false;
32 
33  //default value Z (1 meters)
34  Z = 1;
35 
36  firstTimeIn =0 ;
37 
38  nbr = nbc = 0;
39 }
40 
41 
42 void
43 vpFeatureLuminance::init(unsigned int _nbr, unsigned int _nbc, double _Z)
44 {
45  init() ;
46 
47  nbr = _nbr ;
48  nbc = _nbc ;
49 
50  if((nbr < 2*bord) || (nbc < 2*bord)){
51  throw vpException(vpException::dimensionError, "border is too important compared to number of row or column.");
52  }
53 
54  // number of feature = nb column x nb lines in the images
55  dim_s = (nbr-2*bord)*(nbc-2*bord) ;
56 
57  s.resize(dim_s) ;
58 
59  if (pixInfo != NULL)
60  delete [] pixInfo;
61 
62  pixInfo = new vpLuminance[dim_s] ;
63 
64  Z = _Z ;
65 }
66 
71  : Z(1), nbr(0), nbc(0), bord(10), pixInfo(NULL), firstTimeIn(0), cam()
72 {
73  nbParameters = 1;
74  dim_s = 0 ;
75  flags = NULL;
76 
77  init() ;
78 }
79 
84  : vpBasicFeature(f), Z(1), nbr(0), nbc(0), bord(10), pixInfo(NULL), firstTimeIn(0), cam()
85 {
86  *this = f;
87 }
88 
93 {
94  Z = f.Z;
95  nbr = f.nbr;
96  nbc = f.nbc;
97  bord = f.bord;
99  cam = f.cam;
100  if (pixInfo)
101  delete [] pixInfo;
102  pixInfo = new vpLuminance[dim_s] ;
103  for(unsigned int i=0; i< dim_s; i++)
104  pixInfo[i] = f.pixInfo[i];
105  return (*this);
106 }
107 
112 {
113  if (pixInfo != NULL) delete [] pixInfo ;
114  if (flags != NULL) delete [] flags;
115 }
116 
117 
118 
124 void
126 {
127  this->Z = Z_ ;
128  flags[0] = true;
129 }
130 
131 
137 double
139 {
140  return Z ;
141 }
142 
143 
144 void
146 {
147  cam = _cam ;
148 }
149 
150 
156 void
158 {
159  unsigned int l = 0;
160  double Ix,Iy ;
161 
162  double px = cam.get_px() ;
163  double py = cam.get_py() ;
164 
165 
166  if (firstTimeIn==0)
167  {
168  firstTimeIn=1 ;
169  l =0 ;
170  for (unsigned int i=bord; i < nbr-bord ; i++)
171  {
172  // cout << i << endl ;
173  for (unsigned int j = bord ; j < nbc-bord; j++)
174  { double x=0,y=0;
176  j,i,
177  x,y) ;
178 
179  pixInfo[l].x = x;
180  pixInfo[l].y = y;
181 
182  pixInfo[l].Z = Z ;
183 
184  l++;
185  }
186  }
187  }
188 
189  l= 0 ;
190  for (unsigned int i=bord; i < nbr-bord ; i++)
191  {
192  // cout << i << endl ;
193  for (unsigned int j = bord ; j < nbc-bord; j++)
194  {
195  // cout << dim_s <<" " <<l <<" " <<i << " " << j <<endl ;
196  Ix = px * vpImageFilter::derivativeFilterX(I,i,j) ;
197  Iy = py * vpImageFilter::derivativeFilterY(I,i,j) ;
198 
199  // Calcul de Z
200 
201  pixInfo[l].I = I[i][j] ;
202  s[l] = I[i][j] ;
203  pixInfo[l].Ix = Ix;
204  pixInfo[l].Iy = Iy;
205 
206  l++;
207  }
208  }
209 
210 }
211 
212 
213 
214 
220 void
222 {
223  double x,y,Ix,Iy,Zinv;
224 
225  L.resize(dim_s,6) ;
226 
227  for(unsigned int m = 0; m< L.getRows(); m++)
228  {
229  Ix = pixInfo[m].Ix;
230  Iy = pixInfo[m].Iy;
231 
232  x = pixInfo[m].x ;
233  y = pixInfo[m].y ;
234  Zinv = 1 / pixInfo[m].Z;
235 
236  {
237  L[m][0] = Ix * Zinv;
238  L[m][1] = Iy * Zinv;
239  L[m][2] = -(x*Ix+y*Iy)*Zinv;
240  L[m][3] = -Ix*x*y-(1+y*y)*Iy;
241  L[m][4] = (1+x*x)*Ix + Iy*x*y;
242  L[m][5] = Iy*x-Ix*y;
243  }
244  }
245 }
246 
251 vpMatrix vpFeatureLuminance::interaction(const unsigned int /* select */)
252 {
253  /* static */ vpMatrix L ; // warning C4640: 'L' : construction of local static object is not thread-safe
254  interaction(L) ;
255  return L ;
256 }
257 
258 
266 void
268  vpColVector &e)
269 {
270  e.resize(dim_s) ;
271 
272  for (unsigned int i =0 ; i < dim_s ; i++)
273  {
274  e[i] = s[i] - s_star[i] ;
275  }
276 }
277 
278 
279 
289  const unsigned int /* select */)
290 {
291  /* static */ vpColVector e ; // warning C4640: 'e' : construction of local static object is not thread-safe
292 
293  error(s_star, e) ;
294 
295  return e ;
296 
297 }
298 
299 
300 
301 
307 void
308 vpFeatureLuminance::print(const unsigned int /* select */) 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 
321 
322 
328 void
330  const vpImage<unsigned char> & /* I */,
331  const vpColor &/* color */,
332  unsigned int /* thickness */) const
333 {
334  static int firsttime =0 ;
335 
336  if (firsttime==0)
337  {
338  firsttime=1 ;
339  vpERROR_TRACE("not implemented") ;
340  // Do not throw and error since it is not subject
341  // to produce a failure
342  }
343 }
344 
350 void
352  const vpImage<vpRGBa> & /* I */,
353  const vpColor &/* color */,
354  unsigned int /* thickness */) const
355 {
356  static int firsttime =0 ;
357 
358  if (firsttime==0)
359  {
360  firsttime=1 ;
361  vpERROR_TRACE("not implemented") ;
362  // Do not throw and error since it is not subject
363  // to produce a failure
364  }
365 }
366 
367 
379 {
380  vpFeatureLuminance *feature = new vpFeatureLuminance ;
381  return feature ;
382 }
383 
384 
385 /*
386  * Local variables:
387  * c-basic-offset: 2
388  * End:
389  */
Class that defines the luminance and gradient of a point.
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
virtual ~vpFeatureLuminance()
Destructor.
bool * flags
Ensure that all the parameters needed to compute the iteraction matrix are set.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:183
vpLuminance * pixInfo
Store the image (as a vector with intensity and gradient I, Ix, Iy)
void print(const unsigned int select=FEATURE_ALL) const
unsigned int bord
Border size.
#define vpERROR_TRACE
Definition: vpDebug.h:395
static double derivativeFilterY(const vpImage< T > &I, const unsigned int r, const unsigned int c)
void buildFrom(vpImage< unsigned char > &I)
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
void setCameraParameters(vpCameraParameters &_cam)
unsigned int dim_s
Dimension of the visual feature.
error that can be emited by ViSP classes.
Definition: vpException.h:76
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
double get_py() const
unsigned int nbr
Number of rows.
class that defines what is a visual feature
vpFeatureLuminance * duplicate() const
void set_Z(const double Z)
Class that defines the image luminance visual feature.
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
vpFeatureLuminance & operator=(const vpFeatureLuminance &f)
Generic class defining intrinsic camera parameters.
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
double get_px() const
vpCameraParameters cam
unsigned int nbc
Number of column.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161
static double derivativeFilterX(const vpImage< T > &I, const unsigned int r, const unsigned int c)
Definition: vpImageFilter.h:91
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector s
State of the visual feature.
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94