Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersPerspectiveDepth.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __BIAS_ProjectionParametersPerspectiveDepth_hh__
27 #define __BIAS_ProjectionParametersPerspectiveDepth_hh__
28 
29 #include "bias_config.h"
30 #include <MathAlgo/Interpolator.hh>
31 #include <Base/Common/BIASpragmaStart.hh>
32 #include <Geometry/ProjectionParametersPerspective.hh>
33 
34 namespace BIAS {
35 
36 static unsigned nrOfSplineParameters_ =12;
37 static unsigned nrOfReflectivityParameters_=4;
38 
40  {
41  DEPTH_MODEL_UNDEFINED = -1, // dummy for calibration software
42  DEPTH_MODEL_POLYNOM = 0, // standard depth error model
43  DEPTH_MODEL_LINEAR = 1, // Linear depth error model
44  DEPTH_MODEL_SPLINE = 2, // Splines depth error model
45  DEPTH_MODEL_NONE = 3 // No depth deviation
46  };
47 
48  /** @class ProjectionParametersPerspectiveDepth
49  * @ingroup g_geometry
50  * @brief additional depth calibration parameters for a perspective depth camera
51  * to be used for ToF-(PMD) cameras. Models different depth distortion models which account
52  * for distortions due to sinusoidal assumptions and different surface reflectivities
53  * @author ischiller
54  * @date 01/2009-06/2010 */
55  class BIASGeometry_EXPORT ProjectionParametersPerspectiveDepth
57  public:
58 
59  /** \brief constructor with image width and height
60  * \param width[in]: image width (default=0)
61  * \param height[in]: image height (default=0)
62  * \author ischiller */
63  ProjectionParametersPerspectiveDepth(const unsigned int width = 0,
64  const unsigned int height = 0);
65 
66  /** \brief constructor with depth distortion model
67  * \param model[in]: BIAS_TOF_DEPTH_ERROR_MODEL depth distortion model (Polynom or Spline...)
68  * \author ischiller */
70 
71  /** \brief copy constructor with ProjectionParametersPerspectiveDepth
72  * \param P[in]: ProjectionParametersPerspectiveDepth to init from
73  * \author ischiller */
75  { Init(); *this = P; };
76 
77  /** \brief copy constructor with ProjectionParametersPerspective
78  * \param P[in]: ProjectionParametersPerspective to init from
79  * \author ischiller */
81  {Init(); *this = P; };
82 
83  /** \brief operator = with ProjectionParametersPerspectiveDepth
84  * \param P[in]: ProjectionParametersPerspective to assign from
85  * \return assigned ProjectionParametersPerspectiveDepth
86  * \author ischiller */
90  DepthCalibrationParameters_ = P.DepthCalibrationParameters_;
91  listSplineKnotPoints_ = P.listSplineKnotPoints_;
92  DepthCalibrationModel_= P.DepthCalibrationModel_;
93 
94  ReflectivityCalibrationParameters_ = P.ReflectivityCalibrationParameters_;
95  depthIntNormValues_ = P.depthIntNormValues_;
96  minNormIntCoeffs_ = P.minNormIntCoeffs_;
97  maxNormIntCoeffs_= P.maxNormIntCoeffs_;
98  radiusIntNormCoeffs_ = P.radiusIntNormCoeffs_;
99  minDepth_ = P.minDepth_;
100  maxDepth_ = P.maxDepth_;
101  if(DepthCalibrationModel_ == DEPTH_MODEL_SPLINE)
102  PrepareSpline_();
103  return *this;
104  };
105 
106  /** \brief operator = with ProjectionParametersPerspective
107  * \param P[in]: ProjectionParametersPerspective to assign from
108  * \return assigned ProjectionParametersPerspectiveDepth
109  * \author ischiller */
113  DepthCalibrationParameters_.resize(6, 0.0);
116  DepthCalibrationModel_=DEPTH_MODEL_POLYNOM;
117  // 3 for Reflectivity polynom f(), 2 for radial g()
118  ReflectivityCalibrationParameters_.resize(nrOfReflectivityParameters_, 0.0);
119  minDepth_ = 0.0;
120  maxDepth_ = 15000.0;
121  return *this;
122  };
123 
124  /** \brief destructor which clears all vectors
125  * \author ischiller */
127  DepthCalibrationParameters_.clear();
128  listSplineKnotPoints_.clear();
129  ReflectivityCalibrationParameters_.clear();
130  depthIntNormValues_.clear();
131  minNormIntCoeffs_.clear();
132  maxNormIntCoeffs_.clear();
133  radiusIntNormCoeffs_.clear();
134  };
135 
136  /** \brief Init function called by constructors*/
137  void Init();
138 
139  /** \brief covariant virtual copy constructor for use in Projection */
141  return new ProjectionParametersPerspectiveDepth(*this);
142  }
143 
144  /** \brief Set the depth calibration model, one of BIAS_TOF_DEPTH_ERROR_MODEL
145  * inits the vectors and reserves spaces
146  * \param model[in]: BIAS_TOF_DEPTH_ERROR_MODEL depth distortion model (Polynom or Spline...)
147  * \author ischiller */
148  void SetDepthCalibrationModel(BIAS_TOF_DEPTH_ERROR_MODEL model);
149 
150  /** \brief Set the depth calibration parameters
151  * \param params[in]: the depth distortion parameters must be of correct length according to set model
152  * \param minDepth[in]: the minimum depth used for calibration (default=0.0)
153  * \param maxDepth[in]: the maximum depth used for calibration (default=15000.0)
154  * \author ischiller */
155  void SetDepthCalibrationParameters (const std::vector<double>& params,
156  float minDepth=0.0,
157  float maxDepth=15000.0);
158 
159  /** \brief Set the depth calibration parameters for B-Spline model
160  * \param knots[in]: the knot points of distortion spline must be of correct length (see GetNrOfSplineParameters())
161  * \param controls[in]: the control points of distortion spline must be of correct length (see GetNrOfSplineParameters())
162  * \param minDepth[in]: the minimum depth used for calibration (default=0.0)
163  * \param maxDepth[in]: the maximum depth used for calibration (default=15000.0)
164  * \author ischiller */
165  void SetDepthCalibrationParametersSpline (const std::vector<double>& knots,
166  const std::vector<double>& controls,
167  float minDepth=0.0,
168  float maxDepth=15000.0);
169 
170  /** \brief Get the depth calibration model
171  * \author ischiller */
173  return DepthCalibrationModel_;
174  }
175 
176  /** \brief Get the depth calibration parameters
177  * \param params[out]: the depth distortion parameters, these are the control points in spline model
178  * \author ischiller */
179  void GetDepthCalibrationParameters(std::vector<double> &params){
180  params.clear();
181  for(unsigned i=0;i<DepthCalibrationParameters_.size();i++){
182  params.push_back(DepthCalibrationParameters_[i]);
183  }
184  }
185 
186  /** \brief Get the depth calibration spline knot points
187  * \param knots[out]: the knot points in spline model
188  * \author ischiller */
189  void GetDepthCalibrationSplineKnots(std::vector<double> &knots){
190  knots.clear();
191  for(unsigned i=0;i<listSplineKnotPoints_.size();i++){
192  knots.push_back(listSplineKnotPoints_[i]);
193  }
194  }
195  /** \brief get the minimum and maximum depth values with which the calibration has been done
196  * \param minDepth[out]: minimum depth
197  * \param maxDepth[out]: maximum depth
198  * \author ischiller */
199  void GetMinMaxDepth(float& minDepth, float& maxDepth){
200  minDepth = minDepth_;
201  maxDepth = maxDepth_;
202  }
203 
204  /** \brief sets the reflectivity calibration parameters and Fit polynomials
205  * to radial and reflectivity normalization parameters
206  * \return 0 on sucess, < 0 if polynomial fitting fails
207  * \author ischiller*/
208  int SetReflectivityNormalizationParameters(const std::vector<double>& depthValues,
209  const std::vector<double>& minInt,
210  const std::vector<double>& maxInt,
211  const std::vector<double>& radiusValues,
212  const std::vector<double>& radiusIntensities);
213  /**\brief Set the reflectivity calibration parameters
214  * \param params[in]: the parameters of the reflectivity correction polynomial
215  * \author ischiller
216  * \date 02/2010 */
217  void SetReflectivityCalibrationParameters (const std::vector<double>& params);
218 
219  /**\brief Get the reflectivity calibration parameters
220  * \param params[out]: the parameters of the reflectivity correction polynomial
221  * \author ischiller
222  * \date 02/2010 */
223  void GetReflectivityCalibrationParameters(std::vector<double> &params){
224  params.clear();
225  for(unsigned i=0;i<ReflectivityCalibrationParameters_.size();i++)
226  params.push_back(ReflectivityCalibrationParameters_[i]);
227  }
228  /**\brief Get the reflectivity calibration parameters which define the min reflectivity for
229  * all depths intervals
230  * \param params[out]: the parameters of the reflectivity correction polynomial
231  * \author ischiller
232  * \date 02/2010 */
233  void GetReflectivityMinReflectivities(std::vector<double> &params){
234  params.clear();
235  for(unsigned i=0;i<minNormIntCoeffs_.size();i++)
236  params.push_back(minNormIntCoeffs_[i]);
237  }
238 
239  /**\brief Get the reflectivity calibration parameters which define the max reflectivity for
240  * all depths intervals
241  * \param params[out]: the parameters of the reflectivity correction polynomial
242  * \author ischiller
243  * \date 02/2010 */
244  void GetReflectivityMaxReflectivities(std::vector<double> &params){
245  params.clear();
246  for(unsigned i=0;i<maxNormIntCoeffs_.size();i++)
247  params.push_back(maxNormIntCoeffs_[i]);
248  }
249 
250  /**\brief Get the reflectivity calibration parameters which define the radius vignetting function
251  * \param params[out]: the parameters of the reflectivity correction polynomial
252  * \author ischiller
253  * \date 02/2010 */
254  void GetReflectivityRadiusNormalization(std::vector<double> &params){
255  params.clear();
256  for(unsigned i=0;i<radiusIntNormCoeffs_.size();i++)
257  params.push_back(radiusIntNormCoeffs_[i]);
258  }
259 
260  /**\brief Distort depth value d at image position pos
261  * \param pos[in]: the position in the image
262  * \param d[in][out]: the depth to distort
263  * \param bIsInCartesianCoords[in]: indicates whether image has been transformed to cartesian coordinates */
264  void DistortDepth (HomgPoint2D const &pos, float &d,bool bIsInCartesianCoords=false);
265 
266  /**\brief UnDistort depth value d at image position pos
267  * \param pos[in]: the position in the image
268  * \param d[in][out]: the depth to undistort
269  * \param bIsInCartesianCoords[in]: indicates whether image has been transformed to cartesian coordinates */
270  void UnDistortDepth (HomgPoint2D const &pos, float &d,bool bIsInCartesianCoords=false);
271 
272  /** \brief Undistorts the passed depth map in place. Uses method UnDistortDepth.
273  * \return 0 if everything went smoothly, -1 if parameter's size didn't fit the input image's size.
274  * \param depthMap[in][out]: the depth image to undistort, will be altered
275  * \param bIsInCartesianCoords[in]: indicates whether image has been transformed to cartesian coordinates
276  * \author ischiller **/
277  int UnDistortDepthMapIP(BIAS::Image<float>& depthMap,bool bIsInCartesianCoords=false) ;
278 
279  /** \brief Distorts the passed depth map in place. Uses method DistortDepth.
280  * \return 0 if everything went smoothly, -1 if parameter's size didn't fit the input image's size.
281  * \param depthMap[in][out]: the depth image to distort, will be altered
282  * \param bIsInCartesianCoords[in]: indicates whether image has been transformed to cartesian coordinates
283  * \author ischiller **/
284  int DistortDepthMapIP(BIAS::Image<float>& depthMap,bool bIsInCartesianCoords=false) ;
285 
286 
287  /** \brief Distort Reflectivity value at depth at image offset form center radius
288  * \param depth[in][out]: the depth value, will be altered
289  * \param Reflectivity[in]: the reflectivity at that position
290  * \param radius[in]: current offset from principle point
291  * \author ischiller
292  * \date 02/2010 */
293  void DistortReflectivity(HomgPoint2D const &pos,float &depth,
294  float &Reflectivity,bool bIsInCartesianCoords=false);
295 
296  /** \brief UnDistort Reflectivity value i at image position pos
297  * \param depth[in][out]: the depth value, will be altered
298  * \param Reflectivity[in]: the reflectivity at that position
299  * \param radius[in]: current offset from principle point
300  * \author ischiller
301  * \date 02/2010 */
302  void UnDistortReflectivity(HomgPoint2D const &pos,float &depth,
303  float &Reflectivity,bool bIsInCartesianCoords=false);
304 
305  /** \brief Distort Reflectivity error in depth map
306  * \param depthMap[in][out]: the depth map, will be altered
307  * \param ReflectivityImage[in]: the reflectivity image
308  * \author ischiller
309  * \date 02/2010 */
310  int DistortReflectivityDepthIP(BIAS::Image<float>& depthMap,
311  BIAS::Image<float>& ReflectivityImage,
312  bool bIsInCartesianCoords=false);
313 
314  /** \brief Undistort Reflectivity error in depth map
315  * \param depthMap[in][out]: the depth map, will be altered
316  * \param ReflectivityImage[in]: the reflectivity image
317  * \author ischiller
318  * \date 02/2010 */
319  int UnDistortReflectivityDepthIP(BIAS::Image<float>& depthMap,
320  BIAS::Image<float>& ReflectivityImage,
321  bool bIsInCartesianCoords=false);
322 
323  /** \brief Sets depth distortion to 0
324  * \author ischiller
325  * \date 02/2010 */
326  void SetDepthDistortionToZero();
327 
328  /** \brief Sets depth reflectivity distortion to 0
329  * \author ischiller
330  * \date 02/2010 */
331  void SetReflectivityDepthDistortionToZero();
332 
333  /** \brief checks whether depth distortion is present
334  * \return true if depth distortion is present, false otherwise
335  * \author ischiller
336  * \date 02/2010 */
337  bool HasDepthDistortion() const;
338 
339  /** \brief checks whether depth reflectivity distortion is present
340  * \return true if depth distortion is present, false otherwise
341  * \author ischiller
342  * \date 02/2010 */
343  bool HasReflectivityDistortion() const;
344 
345  /** \brief returns the number of depth error model parameters
346  * \param model[in]: the model for which the number of parameters is requested
347  * \return number of parameters
348  * \author ischiller
349  * \date 02/2010 */
350  static unsigned GetNrOfDepthErrormodelParameters(BIAS_TOF_DEPTH_ERROR_MODEL model);
351 
352  /** \brief returns the number of depth reflectivity error model parameters
353  * \return number of parameters
354  * \author ischiller
355  * \date 02/2010 */
356  static unsigned GetNrOfReflectivityParameters();
357 
358  static std::string GetDepthDistModelString(BIAS_TOF_DEPTH_ERROR_MODEL model);
359 
360 #ifdef BIAS_HAVE_XML2
361  /** @brief specialization of XML block name function */
362  virtual int XMLGetClassName(std::string& TopLevelTag,
363  double& Version) const;
364 
365  /** @brief specialization of XML write function */
366  virtual int XMLOut(const xmlNodePtr Node, XMLIO& XMLObject) const;
367 
368  /** @brief specialization of XML read function */
369  virtual int XMLIn(const xmlNodePtr Node, XMLIO& XMLObject);
370 #endif
371 
372  friend std::ostream& operator<<(std::ostream &os,
374 
375 
376  protected:
378 
379  float minDepth_,maxDepth_;
380  std::vector<double> depthIntNormValues_,minNormIntCoeffs_,maxNormIntCoeffs_;
381  std::vector<double> radiusIntNormValues_, radiusIntNormCoeffs_;
382  void PrepareSpline_();
386  std::vector<double> listSplineKnotPoints_;
387  std::vector<double> DepthCalibrationParameters_;
390  };
391 
392  /////////////// inline code ///////////////////////
393 
394  inline std::ostream& operator<<(std::ostream &os,
396  {
398  os << ppp << std::endl;
399  os << "ProjectionParametersPerspectiveDepth:" << std::endl;
400  switch(p.DepthCalibrationModel_){
401  case DEPTH_MODEL_POLYNOM:
402  os << "Model:"<<"Polynom"<<std::endl;
403  break;
404  case DEPTH_MODEL_LINEAR:
405  os << "Model:"<<"Linear"<<std::endl;
406  break;
407  case DEPTH_MODEL_SPLINE:
408  os << "Model:"<<"Spline"<<std::endl;
409  break;
410  case DEPTH_MODEL_NONE:
411  os << "Model:"<<"None"<<std::endl;
412  break;
414  os << "Model:"<<"Undefined"<<std::endl;
415  break;
416  }
417 
419  os<<"MinDepth:"<<p.minDepth_<<" MaxDepth_:"<<p.maxDepth_<<std::endl;
420  if(p.DepthCalibrationParameters_.size()>0)
421  os<<"DepthCalibration:"<<std::endl;
422  for (unsigned int i=0; i<p.DepthCalibrationParameters_.size(); i++) {
423  os << p.DepthCalibrationParameters_[i]<<" ";
424  }
425  os << std::endl;
427  os<<"Spline Knot Points:"<<std::endl;
428  for (unsigned int i=0; i<p.listSplineKnotPoints_.size(); i++) {
429  os << p.listSplineKnotPoints_[i]<<" ";
430  }
431  os << std::endl;
432  }
433  if(p.ReflectivityCalibrationParameters_.size()>0){
434  os<<"Reflectivity Calibration:"<<std::endl;
435  for (unsigned int i=0; i<p.ReflectivityCalibrationParameters_.size(); i++) {
436  os << p.ReflectivityCalibrationParameters_[i]<<" ";
437  }
438  os << std::endl;
439  }
440  if(p.minNormIntCoeffs_.size()>0){
441  os<<"Minimum Reflectivity Polynom :"<<std::endl;
442  for (unsigned int i=0; i<p.minNormIntCoeffs_.size(); i++) {
443  os << "cmin" << i<<": ";
444  os << p.minNormIntCoeffs_[i]<<" ";
445  }
446  os << std::endl;
447  }
448  if(p.maxNormIntCoeffs_.size()>0){
449  os<<"Maximum Reflectivity Polynom :"<<std::endl;
450  for (unsigned int i=0; i<p.maxNormIntCoeffs_.size(); i++) {
451  os << "cmax" << i<<": ";
452  os << p.maxNormIntCoeffs_[i]<<" ";
453  }
454  os << std::endl;
455  }
456  if(p.radiusIntNormCoeffs_.size()>0){
457  os<<"Radial Vignetting Polynom :"<<std::endl;
458  for (unsigned int i=0; i<p.radiusIntNormCoeffs_.size(); i++) {
459  os << "crad" << i<<": ";
460  os<< p.radiusIntNormCoeffs_[i]<<" ";
461  }
462  os << std::endl;
463  }
464 
465  return os;
466  }
467 
468 
469 
470 } // end namespace
471 
472 #include <Base/Common/BIASpragmaEnd.hh>
473 
474 #endif
475 
static unsigned nrOfSplineParameters_
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
additional depth calibration parameters for a perspective depth camera to be used for ToF-(PMD) camer...
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
void GetReflectivityCalibrationParameters(std::vector< double > &params)
Get the reflectivity calibration parameters.
static unsigned nrOfReflectivityParameters_
void GetReflectivityMaxReflectivities(std::vector< double > &params)
Get the reflectivity calibration parameters which define the max reflectivity for all depths interval...
this class interpolates a function y=f(t) between given control points (the y-values) ...
Definition: Interpolator.hh:71
ProjectionParametersPerspectiveDepth(const ProjectionParametersPerspective &P)
copy constructor with ProjectionParametersPerspective
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
ProjectionParametersPerspectiveDepth & operator=(const ProjectionParametersPerspectiveDepth &P)
operator = with ProjectionParametersPerspectiveDepth
void GetDepthCalibrationSplineKnots(std::vector< double > &knots)
Get the depth calibration spline knot points.
BIAS_TOF_DEPTH_ERROR_MODEL GetDepthCalibrationModel()
Get the depth calibration model.
virtual ProjectionParametersPerspectiveDepth * Clone() const
covariant virtual copy constructor for use in Projection
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
void GetReflectivityMinReflectivities(std::vector< double > &params)
Get the reflectivity calibration parameters which define the min reflectivity for all depths interval...
void GetReflectivityRadiusNormalization(std::vector< double > &params)
Get the reflectivity calibration parameters which define the radius vignetting function.
void GetMinMaxDepth(float &minDepth, float &maxDepth)
get the minimum and maximum depth values with which the calibration has been done ...
ProjectionParametersPerspectiveDepth(const ProjectionParametersPerspectiveDepth &P)
copy constructor with ProjectionParametersPerspectiveDepth
void GetDepthCalibrationParameters(std::vector< double > &params)
Get the depth calibration parameters.
ProjectionParametersPerspective & operator=(const ProjectionParametersPerspective &P)
ProjectionParametersPerspectiveDepth & operator=(const ProjectionParametersPerspective &P)
operator = with ProjectionParametersPerspective
virtual ~ProjectionParametersPerspectiveDepth()
destructor which clears all vectors