Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureLuminance.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
39 #include <visp3/core/vpMatrix.h>
40 #include <visp3/core/vpHomogeneousMatrix.h>
41 #include <visp3/core/vpDisplay.h>
42 #include <visp3/core/vpPixelMeterConversion.h>
43 #include <visp3/core/vpImageConvert.h>
44 #include <visp3/core/vpImageFilter.h>
45 #include <visp3/core/vpException.h>
46 
47 #include <visp3/visual_features/vpFeatureLuminance.h>
48 
49 
62 void
64 {
65  if (flags == NULL)
66  flags = new bool[nbParameters];
67  for (unsigned int i = 0; i < nbParameters; i++) flags[i] = false;
68 
69  //default value Z (1 meters)
70  Z = 1;
71 
72  firstTimeIn =0 ;
73 
74  nbr = nbc = 0;
75 }
76 
77 
78 void
79 vpFeatureLuminance::init(unsigned int _nbr, unsigned int _nbc, double _Z)
80 {
81  init() ;
82 
83  nbr = _nbr ;
84  nbc = _nbc ;
85 
86  if((nbr < 2*bord) || (nbc < 2*bord)){
87  throw vpException(vpException::dimensionError, "border is too important compared to number of row or column.");
88  }
89 
90  // number of feature = nb column x nb lines in the images
91  dim_s = (nbr-2*bord)*(nbc-2*bord) ;
92 
93  s.resize(dim_s) ;
94 
95  if (pixInfo != NULL)
96  delete [] pixInfo;
97 
98  pixInfo = new vpLuminance[dim_s] ;
99 
100  Z = _Z ;
101 }
102 
107  : Z(1), nbr(0), nbc(0), bord(10), pixInfo(NULL), firstTimeIn(0), cam()
108 {
109  nbParameters = 1;
110  dim_s = 0 ;
111  flags = NULL;
112 
113  init() ;
114 }
115 
120  : vpBasicFeature(f), Z(1), nbr(0), nbc(0), bord(10), pixInfo(NULL), firstTimeIn(0), cam()
121 {
122  *this = f;
123 }
124 
129 {
130  Z = f.Z;
131  nbr = f.nbr;
132  nbc = f.nbc;
133  bord = f.bord;
135  cam = f.cam;
136  if (pixInfo)
137  delete [] pixInfo;
138  pixInfo = new vpLuminance[dim_s] ;
139  for(unsigned int i=0; i< dim_s; i++)
140  pixInfo[i] = f.pixInfo[i];
141  return (*this);
142 }
143 
148 {
149  if (pixInfo != NULL) delete [] pixInfo ;
150 }
151 
157 void
159 {
160  this->Z = Z_ ;
161  flags[0] = true;
162 }
163 
164 
170 double
172 {
173  return Z ;
174 }
175 
176 
177 void
179 {
180  cam = _cam ;
181 }
182 
183 
189 void
191 {
192  unsigned int l = 0;
193  double Ix,Iy ;
194 
195  double px = cam.get_px() ;
196  double py = cam.get_py() ;
197 
198 
199  if (firstTimeIn==0)
200  {
201  firstTimeIn=1 ;
202  l =0 ;
203  for (unsigned int i=bord; i < nbr-bord ; i++)
204  {
205  // cout << i << endl ;
206  for (unsigned int j = bord ; j < nbc-bord; j++)
207  { double x=0,y=0;
209  j,i,
210  x,y) ;
211 
212  pixInfo[l].x = x;
213  pixInfo[l].y = y;
214 
215  pixInfo[l].Z = Z ;
216 
217  l++;
218  }
219  }
220  }
221 
222  l= 0 ;
223  for (unsigned int i=bord; i < nbr-bord ; i++)
224  {
225  // cout << i << endl ;
226  for (unsigned int j = bord ; j < nbc-bord; j++)
227  {
228  // cout << dim_s <<" " <<l <<" " <<i << " " << j <<endl ;
229  Ix = px * vpImageFilter::derivativeFilterX(I,i,j) ;
230  Iy = py * vpImageFilter::derivativeFilterY(I,i,j) ;
231 
232  // Calcul de Z
233 
234  pixInfo[l].I = I[i][j] ;
235  s[l] = I[i][j] ;
236  pixInfo[l].Ix = Ix;
237  pixInfo[l].Iy = Iy;
238 
239  l++;
240  }
241  }
242 
243 }
244 
245 
246 
247 
253 void
255 {
256  L.resize(dim_s,6) ;
257 
258  for(unsigned int m = 0; m< L.getRows(); m++)
259  {
260  double Ix = pixInfo[m].Ix;
261  double Iy = pixInfo[m].Iy;
262 
263  double x = pixInfo[m].x ;
264  double y = pixInfo[m].y ;
265  double Zinv = 1 / pixInfo[m].Z;
266 
267  {
268  L[m][0] = Ix * Zinv;
269  L[m][1] = Iy * Zinv;
270  L[m][2] = -(x*Ix+y*Iy)*Zinv;
271  L[m][3] = -Ix*x*y-(1+y*y)*Iy;
272  L[m][4] = (1+x*x)*Ix + Iy*x*y;
273  L[m][5] = Iy*x-Ix*y;
274  }
275  }
276 }
277 
282 vpMatrix vpFeatureLuminance::interaction(const unsigned int /* select */)
283 {
284  /* static */ vpMatrix L ; // warning C4640: 'L' : construction of local static object is not thread-safe
285  interaction(L) ;
286  return L ;
287 }
288 
289 
297 void
299  vpColVector &e)
300 {
301  e.resize(dim_s) ;
302 
303  for (unsigned int i =0 ; i < dim_s ; i++)
304  {
305  e[i] = s[i] - s_star[i] ;
306  }
307 }
308 
309 
310 
320  const unsigned int /* select */)
321 {
322  /* static */ vpColVector e ; // warning C4640: 'e' : construction of local static object is not thread-safe
323 
324  error(s_star, e) ;
325 
326  return e ;
327 
328 }
329 
330 
331 
332 
338 void
339 vpFeatureLuminance::print(const unsigned int /* select */) const
340 {
341  static int firsttime =0 ;
342 
343  if (firsttime==0)
344  {
345  firsttime=1 ;
346  vpERROR_TRACE("not implemented") ;
347  // Do not throw and error since it is not subject
348  // to produce a failure
349  }
350  }
351 
352 
353 
359 void
361  const vpImage<unsigned char> & /* I */,
362  const vpColor &/* color */,
363  unsigned int /* thickness */) const
364 {
365  static int firsttime =0 ;
366 
367  if (firsttime==0)
368  {
369  firsttime=1 ;
370  vpERROR_TRACE("not implemented") ;
371  // Do not throw and error since it is not subject
372  // to produce a failure
373  }
374 }
375 
381 void
383  const vpImage<vpRGBa> & /* I */,
384  const vpColor &/* color */,
385  unsigned int /* thickness */) const
386 {
387  static int firsttime =0 ;
388 
389  if (firsttime==0)
390  {
391  firsttime=1 ;
392  vpERROR_TRACE("not implemented") ;
393  // Do not throw and error since it is not subject
394  // to produce a failure
395  }
396 }
397 
398 
410 {
411  vpFeatureLuminance *feature = new vpFeatureLuminance ;
412  return feature ;
413 }
414 
415 
416 /*
417  * Local variables:
418  * c-basic-offset: 2
419  * End:
420  */
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
virtual ~vpFeatureLuminance()
Destructor.
bool * flags
Ensure that all the parameters needed to compute the iteraction matrix are set.
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.
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
static double derivativeFilterY(const vpImage< T > &I, const unsigned int r, const unsigned int c)
void buildFrom(vpImage< unsigned char > &I)
#define vpERROR_TRACE
Definition: vpDebug.h:391
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void setCameraParameters(vpCameraParameters &_cam)
unsigned int dim_s
Dimension of the visual feature.
error that can be emited by ViSP classes.
Definition: vpException.h:73
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)
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
double get_px() const
vpCameraParameters cam
unsigned int nbc
Number of column.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const
static double derivativeFilterX(const vpImage< T > &I, const unsigned int r, const unsigned int c)
Definition: vpImageFilter.h:86
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:225