ViSP  2.10.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 }
115 
121 void
123 {
124  this->Z = Z_ ;
125  flags[0] = true;
126 }
127 
128 
134 double
136 {
137  return Z ;
138 }
139 
140 
141 void
143 {
144  cam = _cam ;
145 }
146 
147 
153 void
155 {
156  unsigned int l = 0;
157  double Ix,Iy ;
158 
159  double px = cam.get_px() ;
160  double py = cam.get_py() ;
161 
162 
163  if (firstTimeIn==0)
164  {
165  firstTimeIn=1 ;
166  l =0 ;
167  for (unsigned int i=bord; i < nbr-bord ; i++)
168  {
169  // cout << i << endl ;
170  for (unsigned int j = bord ; j < nbc-bord; j++)
171  { double x=0,y=0;
173  j,i,
174  x,y) ;
175 
176  pixInfo[l].x = x;
177  pixInfo[l].y = y;
178 
179  pixInfo[l].Z = Z ;
180 
181  l++;
182  }
183  }
184  }
185 
186  l= 0 ;
187  for (unsigned int i=bord; i < nbr-bord ; i++)
188  {
189  // cout << i << endl ;
190  for (unsigned int j = bord ; j < nbc-bord; j++)
191  {
192  // cout << dim_s <<" " <<l <<" " <<i << " " << j <<endl ;
193  Ix = px * vpImageFilter::derivativeFilterX(I,i,j) ;
194  Iy = py * vpImageFilter::derivativeFilterY(I,i,j) ;
195 
196  // Calcul de Z
197 
198  pixInfo[l].I = I[i][j] ;
199  s[l] = I[i][j] ;
200  pixInfo[l].Ix = Ix;
201  pixInfo[l].Iy = Iy;
202 
203  l++;
204  }
205  }
206 
207 }
208 
209 
210 
211 
217 void
219 {
220  double x,y,Ix,Iy,Zinv;
221 
222  L.resize(dim_s,6) ;
223 
224  for(unsigned int m = 0; m< L.getRows(); m++)
225  {
226  Ix = pixInfo[m].Ix;
227  Iy = pixInfo[m].Iy;
228 
229  x = pixInfo[m].x ;
230  y = pixInfo[m].y ;
231  Zinv = 1 / pixInfo[m].Z;
232 
233  {
234  L[m][0] = Ix * Zinv;
235  L[m][1] = Iy * Zinv;
236  L[m][2] = -(x*Ix+y*Iy)*Zinv;
237  L[m][3] = -Ix*x*y-(1+y*y)*Iy;
238  L[m][4] = (1+x*x)*Ix + Iy*x*y;
239  L[m][5] = Iy*x-Ix*y;
240  }
241  }
242 }
243 
248 vpMatrix vpFeatureLuminance::interaction(const unsigned int /* select */)
249 {
250  /* static */ vpMatrix L ; // warning C4640: 'L' : construction of local static object is not thread-safe
251  interaction(L) ;
252  return L ;
253 }
254 
255 
263 void
265  vpColVector &e)
266 {
267  e.resize(dim_s) ;
268 
269  for (unsigned int i =0 ; i < dim_s ; i++)
270  {
271  e[i] = s[i] - s_star[i] ;
272  }
273 }
274 
275 
276 
286  const unsigned int /* select */)
287 {
288  /* static */ vpColVector e ; // warning C4640: 'e' : construction of local static object is not thread-safe
289 
290  error(s_star, e) ;
291 
292  return e ;
293 
294 }
295 
296 
297 
298 
304 void
305 vpFeatureLuminance::print(const unsigned int /* select */) const
306 {
307  static int firsttime =0 ;
308 
309  if (firsttime==0)
310  {
311  firsttime=1 ;
312  vpERROR_TRACE("not implemented") ;
313  // Do not throw and error since it is not subject
314  // to produce a failure
315  }
316  }
317 
318 
319 
325 void
327  const vpImage<unsigned char> & /* I */,
328  const vpColor &/* color */,
329  unsigned int /* thickness */) const
330 {
331  static int firsttime =0 ;
332 
333  if (firsttime==0)
334  {
335  firsttime=1 ;
336  vpERROR_TRACE("not implemented") ;
337  // Do not throw and error since it is not subject
338  // to produce a failure
339  }
340 }
341 
347 void
349  const vpImage<vpRGBa> & /* I */,
350  const vpColor &/* color */,
351  unsigned int /* thickness */) const
352 {
353  static int firsttime =0 ;
354 
355  if (firsttime==0)
356  {
357  firsttime=1 ;
358  vpERROR_TRACE("not implemented") ;
359  // Do not throw and error since it is not subject
360  // to produce a failure
361  }
362 }
363 
364 
376 {
377  vpFeatureLuminance *feature = new vpFeatureLuminance ;
378  return feature ;
379 }
380 
381 
382 /*
383  * Local variables:
384  * c-basic-offset: 2
385  * End:
386  */
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:199
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:98