ViSP  2.8.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 
30 void
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 
74 {
75  nbParameters = 1;
76  dim_s = 0 ;
77  bord = 10 ;
78  flags = NULL;
79  pixInfo = NULL;
80 
81  init() ;
82 }
83 
88 {
89  if (pixInfo != NULL) delete [] pixInfo ;
90  if (flags != NULL) delete [] flags;
91 }
92 
93 
94 
100 void
102 {
103  this->Z = Z ;
104  flags[0] = true;
105 }
106 
107 
113 double
115 {
116  return Z ;
117 }
118 
119 
120 void
122 {
123  cam = _cam ;
124 }
125 
126 
132 void
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;
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
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
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 
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
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
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 
355 {
356  vpFeatureLuminance *feature = new vpFeatureLuminance ;
357  return feature ;
358 }
359 
360 
361 /*
362  * Local variables:
363  * c-basic-offset: 2
364  * End:
365  */
Class that defines the luminance and gradient of a point.
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
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:174
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:379
void buildFrom(vpImage< unsigned char > &I)
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
static double derivativeFilterX(vpImage< T > &fr, const unsigned int r, const unsigned int c)
void setCameraParameters(vpCameraParameters &_cam)
unsigned int dim_s
Dimension of the visual feature.
error that can be emited by ViSP classes.
Definition: vpException.h:75
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.
static double derivativeFilterY(vpImage< T > &fr, const unsigned int r, const unsigned int c)
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)
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:157
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