Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CameraParam.hh
1 /*
2 $Id: CameraParam.hh,v 2.20 2006/07/31 13:47:40 streckel Exp $
3 */
4 /*
5 This file is part of the BIAS library (Basic ImageAlgorithmS).
6 
7 Copyright (C) 2003-2009 (see file CONTACT for details)
8  Multimediale Systeme der Informationsverarbeitung
9  Institut fuer Informatik
10  Christian-Albrechts-Universitaet Kiel
11 
12 
13 BIAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
17 
18 BIAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 
23 You should have received a copy of the GNU Lesser General Public License
24 along with BIAS; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27 #ifndef __CameraParameter_inc__
28 #define __CameraParameter_inc__
29 #include <bias_config.h>
30 #include <Base/Common/BIASpragmaStart.hh>
31 #include <Geometry/ProjectionParametersIO.hh>
32 
33 #include <vector>
34 #include <string>
35 #include <Base/Debug/Error.hh>
36 #ifdef BIAS_HAVE_XML2
37 # include <Base/Common/XMLIO.hh>
38 #endif
39 
40 #include <Base/Math/Vector2.hh>
41 #include <Base/Geometry/KMatrix.hh>
42 
43 #define CAMERA_PARAMETER_CURRENT_XML_VERSION 2.0
44 
45 namespace BIAS{
46 
47 
48  class BIASImage_EXPORT CameraParam{
49 
50  // static std::string CameraModelName[];
51  // static std::string LensModelName[];
52 
53  public:
54  CameraParam();
55  CameraParam(const CameraParam &cp);
56  /** @brief pass K and image dims to construct a simple parameter file */
57  CameraParam(const KMatrix& K, const int w, const int h);
58 #ifdef BIAS_HAVE_XML2
59  CameraParam(const std::string &filename);
60  // CameraParam(XMLIO &myXML, xmlNodePtr &cameraNode);
61 #endif //BIAS_HAVE_XML2
62 
63  ~CameraParam();
64 
65  // @brief default initialization, ends up with _INVALID_ object
66  void Init();
67  void Init(const CameraParam &cp);
68 
69  void InitPerspective(const std::string CamModel, const int CamID,
70  const std::string LensModel,
71  const int imgWidth, const int imgHeight,
72  const double principalX, const double principalY,
73  const double focallength,
74  const double aspectratio,
75  const double k1, const double k2,
76  const double k3, const double k4,
77  const std::vector<double> &IlluCorrX,
78  const std::vector<double> &IlluCorrY);
79  void InitSpherical(const std::string CamModel, const int CamID,
80  const std::string LensModel,
81  const int imgWidth, const int imgHeight,
82  const double principalX, const double principalY,
83  const double radius,
84  const std::vector<double> &AngleCorrX,
85  const std::vector<double> &AngleCorrY,
86  const std::vector<double> &IlluCorrX,
87  const std::vector<double> &IlluCorrY);
88 
89 #ifdef BIAS_HAVE_XML2
90  // @brief initialization with camera data file
91  int Init(const std::string &filename);
92  // @brief initialization with camera node from pre-parsed data file
93  int Init(XMLIO &myXML, xmlNodePtr &cameraNode);
94 #endif //BIAS_HAVE_
95 
96  /** @brief Set to 'true', if camera has a zoom lens.
97  @author streckel 06/2004*/
98  void SetZoomCamera(const bool zoomCam);
99 
100  /** @brief True, if camera has a zoom lens.
101  @author streckel 06/2004*/
102  bool IsZoomCamera() const;
103 
104  /** @brief Set the current camera zoom, the focal length will be
105  calculated.
106  @author buck */
107  void SetZoom(const double abszoom);
108 
109  /** @brief Set the current camera focal length, the zoom will be
110  calculated.
111  @author buck */
112  void SetFocalLength(const double f);
113 
114  /** @brief Set the zoom and focal length of a zoom camera to the
115  default settings.
116  @author streckel 06/2004*/
117  void SetUnzoomed();
118 
119  /** @brief Set the current camera zoom, the focal length will be
120  calculated.
121  @author buck */
122  double GetZoom() const;
123 
124  /** @brief Get the current camera focal length.
125  @author buck */
126  double GetFocalLength() const;
127 
128  /** @brief Set CCD cell-size in meter.
129  AspectRatio is CS_Y/CS_X
130  @author streckel */
131  void SetCellSize(const double CellSizeX, const double AspectRatio);
132 
133  double GetCellSizeX() {return cd_.cellSizeX_;}
134  double GetCellSizeY() {return cd_.cellSizeY_;}
135 
136  /** @brief Set principal point in pixels relative to top left corner
137  @author streckel */
138  void SetPrincipal(const double x, const double y);
139 
140  /** @brief Set downsampling factor -
141  all get functions will return transformed values
142 
143  E.g. if your image size(width and height) is half the original
144  and the field of view did stay the same, then set factor to 2. <br>
145  CAUTION: The Set-functions still require the original values
146  @author streckel */
147  void SetDownsampling(const double factor);
148 
149  double GetDownsamplingFactor();
150 
151  /** @brief get camera image width.
152  @author buck */
153  unsigned int GetWidth() const;
154  /** @brief get camera image height.
155  @author buck */
156  unsigned int GetHeight() const;
157 
158  inline double GetAspectratio() const {
159  return cd_.aspectratio_;
160  }
161 
162  /** set size of image seperatly */
163  void SetSize(unsigned int w,unsigned int h) {
164  cd_.width_ =w; cd_.height_ = h; }
165 
166  /** @brief get principal point, x in pixels relative to top left corner
167  @author buck */
168  double GetPrincipalX() const;
169  /** @brief get principal point, y in pixels relative to top left corner
170  @author buck */
171  double GetPrincipalY() const;
172 
173  /* @brief Get the Cameras KMatrix corresponding to the current
174  zoom setting
175  @author streckel */
176  BIAS::KMatrix GetKMatrix() const;
177 
178  inline int GetCamID() const {
179  return cd_.CamID_;
180  }
181 
182  inline double GetRadius() const{
183  if (IsSpherical()) {
184  return cd_. radius_/downsamplingFactor_+0.000000001;
185  } else {
186  return -1;
187  }
188  }
189 
190  inline double SetRadius(double r) {
191  if (!IsSpherical()) {
192  BIASERR("Can notset radius for perspective camera");
193  return -1;
194  }
195  cd_.radius_ = r;
196  // should reinit now
197  return 0;
198  }
199 
200 
201  inline void GetDefaultUndistortion(double& f,
202  double& kc1, double& kc2,
203  double& kc3, double& kc4) const
204  {
205  f = cd_.focallengthDef_/downsamplingFactor_+0.000000001;
206  kc1 = cd_.kc1Def_;
207  kc2 = cd_.kc2Def_;
208  kc3 = cd_.kc3Def_;
209  kc4 = cd_.kc4Def_;
210  }
211 
212  inline void GetZoomUndistortion(std::vector<CPDiscreteParam>& vp) const {
213  std::vector<CPDiscreteParam>::const_iterator it;
214  vp.clear();
215  vp.reserve(cd_.knownparams_vect_.size());
216  for (it=cd_.knownparams_vect_.begin();
217  it!=cd_.knownparams_vect_.end();it++) {
218  CPDiscreteParam cpp=*it;
219  cpp.focallength = cpp.focallength/downsamplingFactor_+0.000000001;
220  vp.push_back(cpp);
221  }
222  }
223 
224  inline double GetAspectRatio() const {
225  return cd_.aspectratio_;
226  }
227 
228  inline bool IsSpherical() const { return cd_.LensIsSpherical_;}
229 
230  inline bool IsPerspective() const {return !cd_.LensIsSpherical_;}
231 
232  inline std::vector<double> GetAngleCorrX() const {
233  return cd_.AngleCorrX_;
234  }
235  inline std::vector<double> GetAngleCorrY() const {
236  return cd_.AngleCorrY_;
237  }
238  inline std::vector<double> GetIlluCorrX() const {
239  return cd_.IlluCorrX_;
240  }
241  inline std::vector<double> GetIlluCorrY() const {
242  return cd_.IlluCorrY_;
243  }
244 
245 #ifdef BIAS_HAVE_XML2
246  /** @brief Write all data to a camera data parameter file )
247  @param Filename Name of the XML-camera-data-file,
248  document tag will be to be "Camera"
249  @author streckel 06/2004 */
250  int WriteCameraData(const std::string& Filename) const;
251  /** @brief Add a camera sub-tree-structure to an allready created
252  XML-tree and write the data from (*this) into the tree -
253  called from the rig parameter class.
254  @param myXML points to the XML-Tree
255  @param cameraDataNode points to a "CameraData"-node to append the
256  "Camera"-node
257  @author streckel 06/2004 */
258  //int AddCameraDataToRig(XMLIO &myXML, xmlNodePtr &cameraDataNode) const;
259 
260  /** @brief Read a camera data parameter file and store the data in (*this)
261  @param Filename Name of the XML-camera-data-file,
262  document tag has to be "Camera"
263  @author streckel 06/2004 */
264  int ReadCameraData(const std::string& Filename);
265  /** @brief Read a camera data form a precreated XML-tree and store
266  the data in (*this) - called from the rig parameter class.
267  @param myXML points to the XML-Tree
268  @param rigNode points to a "Camera"-node to evaluate
269  @author streckel 06/2004 */
270  //int ReadCameraData(XMLIO &myXML, xmlNodePtr &cameraNode);
271 #endif //BIAS_HAVE_XML2
272 
273  // Settings for specific cameras
274  void SetData_EVID31_147094();
275  void SetData_OMNITECH_ORIFL_190_3();
276 
277  /** @brief read jpeg EXIF header and set camera parameter
278  @return 0 on success
279  @author koeser 07/2005 */
280  int ReadFromEXIF(const std::string& filename);
281 
282  void DebugOut() const;
283 
284  const CameraData GetCameraData() const {
285  return cd_;
286  }
287 
288  void SetCameraData(const CameraData &cd) {
289  cd_ = cd;
290  }
291 
292  protected:
294 
295  //0.5 means upsample, 2 means half size, 4 one forth ....
297 
298  // calibration settings for the current zoom setting of a zoom camera
299  // zoom and focallengthZoom are dependend:
300  // if zoom is set, focallengthZoom will be calculated and vice versa
301  // focal length is stored in pixel
302  double zoom_;
304 
305  double InterpolateFocalLength_(); // w/ given abszoom
306  double InterpolateAbsZoom_(); // w/ given focal length
307 
308 // #ifdef BIAS_HAVE_XML2
309 // int ReadCameraDataV0_8(XMLIO &myXML, xmlNodePtr &cameraNode);
310 // int ReadCameraDataV1_0(XMLIO &myXML, xmlNodePtr &cameraNode);
311 // int AddCameraDataToXMLTree(XMLIO &myXML, xmlNodePtr &rootNode) const;
312 // #endif //BIAS_HAVE_XML2
313 
314  };
315 
316 }
317 
318 #include <Base/Common/BIASpragmaEnd.hh>
319 #endif
double GetCellSizeY()
Definition: CameraParam.hh:134
double SetRadius(double r)
Definition: CameraParam.hh:190
void GetZoomUndistortion(std::vector< CPDiscreteParam > &vp) const
Definition: CameraParam.hh:212
std::vector< double > GetAngleCorrX() const
Definition: CameraParam.hh:232
double downsamplingFactor_
Definition: CameraParam.hh:296
double GetAspectRatio() const
Definition: CameraParam.hh:224
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
std::vector< double > GetAngleCorrY() const
Definition: CameraParam.hh:235
void SetCameraData(const CameraData &cd)
Definition: CameraParam.hh:288
int GetCamID() const
Definition: CameraParam.hh:178
enum BIAS::LensModel_e LensModel
double GetCellSizeX()
Definition: CameraParam.hh:133
std::vector< double > GetIlluCorrY() const
Definition: CameraParam.hh:241
bool IsSpherical() const
Definition: CameraParam.hh:228
std::vector< double > GetIlluCorrX() const
Definition: CameraParam.hh:238
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
double GetAspectratio() const
Definition: CameraParam.hh:158
const CameraData GetCameraData() const
Definition: CameraParam.hh:284
double GetRadius() const
Definition: CameraParam.hh:182
bool IsPerspective() const
Definition: CameraParam.hh:230
void SetSize(unsigned int w, unsigned int h)
set size of image seperatly
Definition: CameraParam.hh:163
void GetDefaultUndistortion(double &f, double &kc1, double &kc2, double &kc3, double &kc4) const
Definition: CameraParam.hh:201