Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersIO.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_ProjectionParametersIO_hh__
27 #define __BIAS_ProjectionParametersIO_hh__
28 #include "bias_config.h"
29 
30 #include <Base/Common/BIASpragmaStart.hh>
31 #include <Base/Math/Vector3.hh>
32 #include <Base/Geometry/HomgPoint2D.hh>
33 
34 #include <Base/Debug/Debug.hh>
35 #ifdef BIAS_HAVE_XML2
36 # include <Base/Common/XMLBase.hh>
37 #endif
38 
39 #include <Base/Geometry/KMatrix.hh>
40 
41 #define CAMERA_PARAMETER_CURRENT_XML_VERSION 2.0
42 #define RIG_PARAMETER_CURRENT_XML_VERSION 1.0
43 
44 namespace BIAS {
45 
46 #ifndef __BIAS_CPDiscreteParam__
47 #define __BIAS_CPDiscreteParam__
48 
49  struct BIASGeometry_EXPORT CPDiscreteParam {
50  double zoom;
51  double focallength;
52  // radial/tangential distortion parameters.
53  // 4th order model of brown.
54  double kc1,kc2,kc3,kc4;
55  };
56 #endif
57 
58  struct BIASGeometry_EXPORT SensorData {
59 
60  // center and rotation relative to a common rig pose
62  double PoseInRigYaw_;
65 
66  };
67 
68  struct BIASGeometry_EXPORT CameraData {
69 
70  // Which camera if used?
71  std::string CamModel_;
72  int CamID_;
73  std::string LensModel_;
74 
75  // do we have zoom or fixed optics?
77 
78  // Lens can be Spherical or Perspective
80 
81  // width and height of the camera image
82  unsigned int width_, height_;
83 
84  // filled by inheriting camera model
85  double aspectratio_;
86 
87  // size of the single CCD-sensor-cells in meter
88  double cellSizeX_, cellSizeY_;
89 
90  // Principal Point Pixel Coordinates (one for all zoom settings)
91  double principalX_, principalY_;
92 
93  // image radius if image is spherical
94  double radius_;
95 
96  // Maximum image angle of the fisheye camera
97  double MaxCamAngle_;
98 
99  // only for perspective lenses
100  // standard settings for non zoom lenses or
101  // for zoom default state
102  // focal length is stored in pixel for cellSizeX
104  double kc1Def_,kc2Def_,kc3Def_,kc4Def_;
105 
106  // array of camera calibration constants for zoom cameras
107  std::vector<CPDiscreteParam> knownparams_vect_;
108 
109  // illumination vignette correction
110  // x is distance in pixel from principal point
111  // y is illumination correction factor
112  std::vector<double> IlluCorrX_;
113  std::vector<double> IlluCorrY_;
114 
115  // Only for sphere images:
116  // Calibration measurements for angle correction
117  std::vector<double> AngleCorrX_;
118  std::vector<double> AngleCorrY_;
119  // polynome coefficients from matlab toolbox
120  double acCoeff0_,acCoeff1_,acCoeff2_,acCoeff3_,acCoeff4_;
121 
122  // center and rotation relative to a common rig pose
127 
128  };
129 
130  class BIASGeometry_EXPORT ProjectionParametersIO{
131 
132  public:
133 
134  /** @brief read bbc's freeD date from an open stream
135  @return 0 on success
136  @author koeser 11/2006 */
137  static int ReadFromBBCStream(std::ifstream& infile,
138  CameraData& cd,
139  const double& addppx=0.0,
140  const double& addppy=0.0,
141  const bool silent = false);
142 
143  /** @brief read bbc's freeD date from a file
144  @return 0 on success
145  @author koeser 11/2006 */
146  static int ReadFromBBC(const std::string& filename,
147  CameraData& cd,
148  const double& addppx=0.0,
149  const double& addppy=0.0,
150  const bool silent = false);
151 
152  /** @brief read jpeg EXIF header and set camera parameter
153  @return 0 on success
154  @author koeser 07/2005 */
155  static int ReadFromEXIF(const std::string& filename,
156  CameraData& cd);
157 
158  /** @brief pass K and image dims to construct a simple parameter file */
159  static int SetFromKMatrix(const BIAS::KMatrix& K,
160  const int w, const int h,
161  CameraData& cd);
162 
163 #ifdef BIAS_HAVE_XML2
164 
165  /** @brief Write all data camera data and camera positions in the rig
166  to a rig parameter file in XML-notation
167  @param Filename Name of the XML-rig-data-file,
168  document tag will be to be "Rig"
169  @author streckel 06/2004 */
170  static int WriteRigData(const std::string &filename,
171  const std::vector<CameraData>& vcd,
172  const std::vector<SensorData>& vsd=
173  std::vector<SensorData>(0,SensorData()));
174 
175  /** @brief Write all data to a camera data parameter file )
176  @param Filename Name of the XML-camera-data-file,
177  document tag will be to be "Camera"
178  @author streckel 06/2004 */
179  static int WriteCameraData(const std::string& Filename,
180  const CameraData& cd);
181 
182  /** @brief Read a rig parameter file and store the data in (*this)
183  the Camera-, Center-, RMatrix-, and KMatrix-Vectors are
184  reset from the file.
185  @param Filename Name of the XML-camera-data-file,
186  document tag has to be "Rig"
187  @author streckel 06/2004 */
188  static int ReadRigData(const std::string &filename,
189  std::vector<CameraData>& vcd,
190  const bool silent = false);
191 
192  static int ReadRigData(const std::string &filename,
193  std::vector<CameraData>& vcd,
194  std::vector<SensorData>& vsd,
195  const bool silent = false);
196 
197  /** @brief Read a camera data parameter file and store the data in (*this)
198  @param Filename Name of the XML-camera-data-file,
199  document tag has to be "Camera"
200  @author streckel 06/2004 */
201  static int ReadCameraData(const std::string& Filename,
202  CameraData& cd,
203  const bool silent = false);
204 
205 #endif //BIAS_HAVE_XML2
206 
207 
208  // Settings for specific cameras (only for testing)
209  static void SetData_EVID31_147094(CameraData& cd);
210  static void SetData_OMNITECH_ORIFL_190_3(CameraData& cd);
211  static void SetData_DummyRig(std::vector<CameraData>& vcd);
212 
213 protected:
214 
215  #ifdef BIAS_HAVE_XML2
216 
217  /** @brief Read a camera data form a precreated XML-tree and store
218  the data in (*this) - called from the rig parameter class.
219  @param myXML points to the XML-Tree
220  @param cameraNode points to a "Camera"-node to evaluate
221  @author streckel 06/2004 */
222  static int ReadCameraData(XMLIO &myXML, xmlNodePtr &cameraNode,
223  CameraData& cd,
224  const bool silent = false);
225 
226  /** @brief Add a camera sub-tree-structure to an allready created
227  XML-tree and write the data from (*this) into the tree -
228  called from the rig parameter class.
229  @param myXML points to the XML-Tree
230  @param cameraDataNode points to a "CameraData"-node to append the
231  "Camera"-node
232  @author streckel 06/2004 */
233  static int AddCameraDataToRig(XMLIO &myXML, xmlNodePtr &cameraDataNode,
234  const CameraData &cd);
235 
236  // called by WriteCameraData and AddCameraDataToRig to add
237  //the data of a certain camera to a node
238  static int AddCameraDataToNode(XMLIO &myXML, xmlNodePtr &rootNode,
239  const CameraData &cd);
240 #endif // BIAS_HAVE_XML2
241 
242  /** @brief default zero initialization for a single camera */
243  static void Initialize(CameraData &cd);
244 
245  /** @brief default zero initialization for a single sensor */
246  static void InitializeSensor(SensorData &sd);
247 
248  /** @brief Reading old file versions */
249  static int ReadRigDataV0_8(const std::string &filename,
250  std::vector<CameraData>& vcd,
251  const bool silent = false);
252 #ifdef BIAS_HAVE_XML2
253 
254  static int ReadCameraDataV1_0(XMLIO &myXML, xmlNodePtr &cameraNode,
255  CameraData& cd,
256  const bool silent = false);
257  static int ReadCameraDataV0_8(XMLIO &myXML, xmlNodePtr &cameraNode,
258  CameraData& cd,
259  const bool silent = false);
260 #endif // BIAS_HAVE_XML2
261 
262  /** transform polynome coefficients from matlab toolbox
263  (see: http://asl.epfl.ch/~scaramuz/research/Davide_Scaramuzza_files/Research/OcamCalib_Tutorial.htm)
264  to spline nodes for faster lookup vis LUT
265  @author streckel 07/2006 */
266  static int InitAngleCorrFromPoly_(CameraData &cd);
267 
268  };
269 
270 } // end namespace
271 
272  /** @relates ProjectionParametersIO
273  @brief standard ostream operator for dumping ProjectionParametersIO
274  to screen */
275 BIASGeometry_EXPORT std::ostream& operator<<(std::ostream &os, std::vector<BIAS::CameraData>& vcd);
276 BIASGeometry_EXPORT std::ostream& operator<<(std::ostream &os, std::vector<BIAS::SensorData>& vsd);
277 BIASGeometry_EXPORT std::ostream& operator<<(std::ostream &os, BIAS::CameraData& cd);
278 BIASGeometry_EXPORT std::ostream& operator<<(std::ostream &os, BIAS::SensorData& sd);
279 
280 #include <Base/Common/BIASpragmaEnd.hh>
281 
282 #endif
283 
std::vector< double > IlluCorrY_
std::vector< double > IlluCorrX_
std::ostream & operator<<(std::ostream &os, const AppData &ad)
std::vector< double > AngleCorrX_
BIAS::Vector3< double > PoseInRigCenter_
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
std::vector< CPDiscreteParam > knownparams_vect_
BIAS::Vector3< double > PoseInRigCenter_
std::vector< double > AngleCorrY_
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48