Image Component Library (ICL)
IntrinsicCalibrator.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLIO/src/ICLIO/IntrinsicCalibrator.h **
10 ** Module : ICLIO **
11 ** Authors: Christian Groszewski **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/BasicTypes.h>
34 #include <ICLUtils/Macros.h>
35 #include <ICLUtils/Uncopyable.h>
36 #include <ICLUtils/ConfigFile.h>
37 #include <ICLUtils/StackTimer.h>
38 #include <ICLUtils/Array2D.h>
39 #include <ICLMath/DynMatrix.h>
40 #include <ICLMath/DynMatrixUtils.h>
41 #include <ICLCore/Img.h>
43 
44 namespace icl{
45  namespace io{
46 
55 
56  public:
59 
61  Result(){}
62 
64  Result(const std::vector<double> &params, const utils::Size &size):
65  ImageUndistortion("MatlabModel5Params",params,size){}
66 
68 
70  double getFocalLengthX() const { return getParams()[0]; }
72 
74  double getFocalLengthY() const { return getParams()[1]; }
76 
78  double getPrincipalX() const { return getParams()[2]; }
80 
83  double getPrincipalY() const { return getParams()[3]; }
85 
88  double getSkew() const { return getParams()[4]; }
89 
91 
94  double getK1() const { return getParams()[5]; }
96 
99  double getK2() const { return getParams()[6]; }
101 
104  double getK3() const { return getParams()[9]; }
106 
109  double getP1() const { return getParams()[7]; }
111 
114  double getP2() const { return getParams()[8]; }
115  };
116  private:
118  class Data;
119  Data *m_data;
122 
124 
132  void rigid_motion(const math::DynMatrix<icl64f> &X,
133  const math::DynMatrix<icl64f> &om,
134  const math::DynMatrix<icl64f> &T,
136 
138 
154  void project_points2(const math::DynMatrix<icl64f> &X, const math::DynMatrix<icl64f> &om, const math::DynMatrix<icl64f> &T,
155  const math::DynMatrix<icl64f> &f, const math::DynMatrix<icl64f> &c, const math::DynMatrix<icl64f> &k, const double alpha,
158 
160 
165  void comp_distortion_oulu(const math::DynMatrix<icl64f> xd,const math::DynMatrix<icl64f> k, math::DynMatrix<icl64f> &x);
166 
168 
173  void compute_homography(const math::DynMatrix<icl64f> &m, const math::DynMatrix<icl64f> &M, math::DynMatrix<icl64f> &H);
174 
176 
181  void optimize(const math::DynMatrix<icl64f> &impoints, const math::DynMatrix<icl64f> &worldPoints, double *params);
182 
184 
192  void init_intrinsic_param(const math::DynMatrix<icl64f> &x, const math::DynMatrix<icl64f> &X,
194 
196 
208  void comp_ext_calib(const math::DynMatrix<icl64f> &x_kk, const math::DynMatrix<icl64f> &X_kk, const math::DynMatrix<icl64f> &fc,
209  const math::DynMatrix<icl64f> &cc, const math::DynMatrix<icl64f> &kc, const double alpha_c, const double thresh_cond,
211 
213 
221  void normalize_pixel(const math::DynMatrix<icl64f> x_kk, const math::DynMatrix<icl64f> fc, const math::DynMatrix<icl64f> cc,
222  const math::DynMatrix<icl64f> kc,const double alpha_c, math::DynMatrix<icl64f> &xn);
223 
225 
231 
233  /*
234  *@param in rotation matrix or vector
235  *@param out rotation matrix or vector
236  *@param dout derivative of rotation
237  */
238 
239  void rodrigues(const math::DynMatrix<icl64f> &in,math::DynMatrix<icl64f> &out, math::DynMatrix<icl64f> &dout);
240 
242 
253  void compute_extrinsic_init(const math::DynMatrix<icl64f> &x_kk, const math::DynMatrix<icl64f> &X_kk, const math::DynMatrix<icl64f> &fc,
254  const math::DynMatrix<icl64f> &cc, const math::DynMatrix<icl64f> &kc, const double &alpha_c,
256 
258  /*
259  * @param x_kk image coordinates
260  * @param X_kk world coordinates
261  * @param fc focal length
262  * @param cc principal point
263  * @param kc distortion coefficients
264  * @param alpha_c skew
265  * @param MaxIter maximum number of iterations for optimazation
266  * @param omckk rotation vector
267  * @param Tckk translation vector
268  * @param Rckk rotation matricx
269  */
270  void compute_extrinsic_refine(const math::DynMatrix<icl64f> &omc_init, const math::DynMatrix<icl64f> &Tc_init,
272  const math::DynMatrix<icl64f> &kc,const double alpha_c, const int MaxIter, double thresh_cond,
274 
275  public:
276 
278 
285  IntrinsicCalibrator(unsigned int boardWidth=6, unsigned int boardHeight=9, unsigned int boardCount=8,
286  unsigned int imageWidth=640, unsigned int imageHeight=480);
287 
290 
292 
297  Result calibrate(const math::DynMatrix<icl64f> &impoints, const math::DynMatrix<icl64f> &worldpoints);
298 
300 
303  void saveIntrinsics(const std::string &filename);
304 
306 
309  void loadIntrinsics(const std::string &filename);
310 
312 
319  void resetData(unsigned int boardWidth, unsigned int boardHeight,
320  unsigned int boardCount,unsigned int imageWidth ,unsigned int imageHeight);
321 
323  Result getResult() const {
324  return m_calres;
325  }
326 
327  //2d coordinates in picture
329  //grid of 2d coords in picture
331 
333  // list of detected images (row-major order of points)
334  std::vector<DetectedGrid> data;
335  //imagesize of data
337  };
338 
340 
343  static Result optimize(const CalibrationData &data);
344 
345  };
346  } // namespace io
347 }
348 
Definition: IntrinsicCalibrator.h:332
std::vector< DetectedGrid > data
Definition: IntrinsicCalibrator.h:334
Powerful and highly flexible matrix class implementation.
Definition: FixedMatrix.h:172
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
utils::Size imageSize
Definition: IntrinsicCalibrator.h:336
double getFocalLengthX() const
returns focal length for x direction
Definition: IntrinsicCalibrator.h:70
double mean(ForwardIterator begin, ForwardIterator end)
computes the mean value of a data range
Definition: MathFunctions.h:78
double getK2() const
returns second radial distortion param
Definition: IntrinsicCalibrator.h:99
ICLCore_API void cc(const ImgBase *src, ImgBase *dst, bool roiOnly=false)
Color conversion from source to destination image.
double getP2() const
returns second tangential distortion param
Definition: IntrinsicCalibrator.h:114
utils::Array2D< Pos2D > DetectedGrid
Definition: IntrinsicCalibrator.h:330
Result()
create a null result
Definition: IntrinsicCalibrator.h:61
double getK3() const
returns third radial distortion param
Definition: IntrinsicCalibrator.h:104
math::FixedMatrix< double, 1, 2 > Pos2D
Definition: IntrinsicCalibrator.h:328
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
Result getResult() const
return the result of computation
Definition: IntrinsicCalibrator.h:323
Result m_calres
struct for handling result of computation
Definition: IntrinsicCalibrator.h:121
#define ICLIO_API
Definition: CompatMacros.h:176
Size class of the ICL.
Definition: Size.h:61
double getPrincipalX() const
returns new computed principal point x component
Definition: IntrinsicCalibrator.h:78
double getFocalLengthY() const
returns focal length for y direction
Definition: IntrinsicCalibrator.h:74
Simple 2D-Array class that provides shallow copy per default.
Definition: Array2D.h:61
double getK1() const
returns first radial distortion param
Definition: IntrinsicCalibrator.h:94
Definition: IntrinsicCalibrator.h:54
double getSkew() const
returns the skew
Definition: IntrinsicCalibrator.h:88
Simple struct for handle result of computation of intrinsics.
Definition: IntrinsicCalibrator.h:58
Result(const std::vector< double > &params, const utils::Size &size)
create a result with given parameters
Definition: IntrinsicCalibrator.h:64
Definition: ImageUndistortion.h:39
double getPrincipalY() const
returns new computed principal point y component
Definition: IntrinsicCalibrator.h:83
Data * m_data
Definition: IntrinsicCalibrator.h:118
double getP1() const
returns first tangential distortion param
Definition: IntrinsicCalibrator.h:109