Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Camera.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 BIAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 BIAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with BIAS; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 #ifndef __BIASCAMERA_HH__
25 #define __BIASCAMERA_HH__
26 #include "bias_config.h"
27 
28 #include <Base/Image/Image.hh>
29 #include <Geometry/PMatrix.hh>
30 #include <Geometry/Projection.hh>
31 #include <Base/Geometry/KMatrix.hh>
32 #include <Geometry/RMatrix.hh>
33 #include <Base/Math/Vector3.hh>
34 #include <Base/Image/MetaData.hh>
35 
36 //#ifdef BIAS_DAIMLERCHRYSLER
37 #include "DCData.hh"
38 //#endif
39 
40 #define D_CAM_DCPTU 0x0001
41 #define D_CAM_DCINERT 0x0002
42 #define D_CAMERA_METADATA 0x0004
43 #define D_CAM_IO 0x0008
44 
45 namespace BIAS {
46  /** @class Camera
47  @ingroup g_image
48  @brief extends the Image by MetaData support (e.g. PMatrix,
49  sensor data, etc.)
50 
51  This class Camera extends Image with
52  - accurate timestamps
53  - P-matrix support
54  - C, R, K matrix support (camera center, -rotation, -calibration)
55  - anything usefull representing a camera
56 
57  After reading a file with such meta data (call it MYDATA) you can call
58  Camera::IsMYDATAValid() to find out if there is MYDATA in your camera
59  object. If so, call Camera::GetMYDATA().
60  Remark: In old image files written by BIAS, invalid meta data has been
61  attached as zero entries, e.g. PMatrix=0,0,0,0,0,0,0,0,0,0,0,0 means
62  that there was no PMatrix available.
63 
64  To add/update meta information data to your camera, call
65  Camera::AddMYDATA(mydataobject) to attach it to the camera object.
66  Before writing the camera, you must call
67  Camera::UpdateMetaData() to tell the Camera to convert the current
68  data into the BIAS::MetaData format, which is then written.
69 
70  See ImageIO for the file types where such meta data information can be
71  stored and read, maybe mip or pgm/ppm.
72  */
73  template <class StorageType>
74  class BIASImage_EXPORT Camera : public Image<StorageType>
75  {
76  public:
77  Camera();
78  explicit Camera(const ImageBase& img);
79  Camera(const Camera<StorageType> &src);
80  virtual ~Camera();
81 
82  /** virtual covariant copy constructor which produces the same type of
83  object as the template object (Image, Camera, ...).
84  Must be implemented in all derived classes and since some people do
85  work with ImageBase objects, it is also implemented there.
86  The caller is responsible to delete the clone.
87  @author koeser 06/2006 */
88  virtual Camera<StorageType>* Clone() const
89  { return new Camera<StorageType>(*this); }
90 
91  /** @brief After ImageIO::Load() operated on AppData_, this method fills
92  P_, Timestamp, DC_*, ...
93  @param bUse2x64bitTS: use 2x(long long uint) timestamps (else 2xint)
94  */
95  int ParseMetaData(bool bUse2x64bitTS=true);
96 
97  /** @brief copy P_ and co. back to MetaData before
98  useful before ImageIO::Write() or ImageIO::ExportImage
99  */
100  int UpdateMetaData();
101 
102  inline int SetP(const PMatrix& matP) { PValid_=true; P_=matP; return 0;};
103 
104  inline const BIAS::PMatrix& GetP() const { return P_; } ;
105 
106  inline int SetProj(const Projection& Proj) { ProjValid_=true;
107  Proj_=Proj; return 0;};
108 
109  inline const BIAS::Projection& GetProj() const { return Proj_; } ;
110 
111 
112  inline void SetASCIIString(const std::string& ASCIIString)
113  {
114  ASCIIString_=ASCIIString; ASCIIValid_=true;
115  }
116 
117  inline std::string GetASCIIString()
118  {
119  return ASCIIString_;
120  }
121 
122 
123  /// @brief Set time and ensure correct format (seconds and useconds after 'sec')
124  inline void SetTime(unsigned long long int sec, unsigned long long int usec)
125  {
126  TimeSec_ = sec + usec/1000000;
127  TimeUSec_ = usec%TimeSec_;
128  TimeValid_ = true;
129  }
130 
131  /// @brief set time from double (in seconds and useconds after full seconds)
132  inline void SetTime(double sec)
133  {
134  TimeValid_ = true;
135  TimeSec_ = static_cast<int> (sec);
136  TimeUSec_ = static_cast<int> (rint((sec-(double)TimeSec_)*1000000.0));
137  }
138 
139  inline void GetTime(unsigned long long int &sec, unsigned long long int &usec)
140  {
141  sec = TimeSec_;
142  usec = TimeUSec_;
143  }
144 
145  inline double GetTime() const
146  {
147  return double(TimeSec_) + double(TimeUSec_)/1000000.0;
148  }
149 
150 
151  inline void SetOrientation(const float ori[3])
152  { Orientation_[0] = ori[0]; Orientation_[1] = ori[1];
153  Orientation_[2] = ori[2]; OrientationValid_=true;};
154 
155  inline void SetOrientation(const BIAS::Vector3<double> &ori) {
156  Orientation_[0] = float(ori[0]); Orientation_[1] = float(ori[1]);
157  Orientation_[2] = float(ori[2]); OrientationValid_=true;
158  }
159 
160  inline void GetOrientation(float &o0,float &o1,float &o2) const {
161  o0 = Orientation_[0]; o1 = Orientation_[1]; o2 = Orientation_[2];}
162 
163  inline void GetOrientation(BIAS::Vector3<double> &ori) const {
164  ori[0] = Orientation_[0]; ori[1] = Orientation_[1];
165  ori[2] = Orientation_[2];}
166 
167  inline void SetC(const Vector3<double>& C) { _C = C; CValid_ = true;};
168  inline const Vector3<double>& GetC() const { return _C; };
169 
170  inline void SetR(const RMatrix& R) { _R = R; RValid_ =true; };
171  inline const RMatrix& GetR() const { return _R; };
172 
173  inline void SetK(const KMatrix& K) { _K = K; KValid_=true;};
174  inline const KMatrix& GetK() const { return _K; };
175 
176  inline void Setf(const double& focal) {_f = focal; fValid_=true;};
177  inline const double Getf() const { return _f; };
178 
179 //#ifdef BIAS_DAIMLERCHRYSLER
180  inline void SetPTU(DC_ptu& p) { ptu = p; ptuValid_ = true;};
181  inline const DC_ptu& GetPTU() const { return ptu; };
182 
183  inline void SetInertial(DC_inertial& i) {
184  inertial = i; inertialValid_=true; };
185  inline const DC_inertial& GetInertial() const { return inertial; };
186 
187  inline void SetGPS(DC_GPS& g) {gps = g; gpsValid_=true;};
188  inline const DC_GPS& GetGPS() const { return gps; };
189 //#endif
190 
191  Camera<StorageType>& operator=(const Camera<StorageType> &src);
192 
193  /// @brief see whats in the camera, for debug
194  void PrintAppData(std::ostream &os) ;
195 
196  /** @brief Is field of data valid or unknown ? if false,
197  the return value of the Get...()-function is undefined */
198  inline bool IsTimeValid() const { return TimeValid_;}
199  /** @brief Is field of data valid or unknown ? if false,
200  the return value of the Get...()-function is undefined */
201  inline bool IsOrientationValid() const { return OrientationValid_;}
202  /** @brief Is field of data valid or unknown ? if false,
203  the return value of the Get...()-function is undefined */
204  inline bool IsPValid() const { return PValid_;}
205  /** @brief Is field of data valid or unknown ? if false,
206  the return value of the Get...()-function is undefined */
207  inline bool IsKValid() const { return KValid_;}
208  /** @brief Is field of data valid or unknown ? if false,
209  the return value of the Get...()-function is undefined */
210  inline bool IsRValid() const { return RValid_;}
211  /** @brief Is field of data valid or unknown ? if false,
212  the return value of the Get...()-function is undefined */
213  inline bool IsCValid() const { return CValid_;}
214  /** @brief Is field of data valid or unknown ? if false,
215  the return value of the Get...()-function is undefined */
216  inline bool IsPointValid() const { return PointValid_;}
217  /** @brief Is field of data valid or unknown ? if false,
218  the return value of the Get...()-function is undefined */
219  inline bool IsfValid() const { return fValid_;}
220 
221  inline bool IsProjValid() const { return ProjValid_;}
222 
223  BIAS::UUID const GetReferenceUUID() const {return RefUUID_;};
224  void SetReferenceUUID(const BIAS::UUID &uid) {RefUUID_ = uid;};
225 
226 //#ifdef BIAS_DAIMLERCHRYSLER
227  inline bool IsptuValid() { return ptuValid_;}
228  inline bool IsinertialValid() { return inertialValid_;}
229  inline bool IsgpsValid() { return gpsValid_;}
230 //#endif
231 
232  protected:
233  /// @brief called by constructors to init all fields
234  void Init_();
235 
236  /// ASCII multifunctional string
237  std::string ASCIIString_;
238  /// is correspondig field of data valid or unknown ?
240 
241  /// time stamp in seconds
242  //long int TimeSec_;
243  unsigned long long int TimeSec_;
244  /// time stamp in microseconds
245  // long int TimeUSec_;
246  unsigned long long int TimeUSec_;
247  /// is correspondig field of data valid or unknown ?
249 
250  /// orientation data from sensor ?
251  float Orientation_[3];
252  /// is correspondig field of data valid or unknown ?
254 
255  /// pmatrix, maybe non-metric
257  /// is correspondig field of data valid or unknown ?
258  bool PValid_;
259 
260  // new projection, will replace P_ soon
263 
264  /// camera calibration with internals
266  /// is correspondig field of data valid or unknown ?
267  bool KValid_;
268 
269  /// camera orientation
271  /// is correspondig field of data valid or unknown ?
272  bool RValid_;
273 
274  /// camera center in wcs
276  /// is correspondig field of data valid or unknown ?
277  bool CValid_;
278 
279  /// a point, it is up to you what you put in
281  /// is correspondig field of data valid or unknown ?
283 
284  /// focal length in m
285  double _f;
286  /// is correspondig field of data valid or unknown ?
287  bool fValid_;
288 
289  // the uuid of a related image. E.g.:if this is a depth map, this
290  // can reference the corresponding image.
292 
293 //#ifdef BIAS_DAIMLERCHRYSLER
294  // car sensor data from DC
296  /// is correspondig field of data valid or unknown ?
297  bool ptuValid_;
298 
300  /// is correspondig field of data valid or unknown ?
302 
304  /// is correspondig field of data valid or unknown ?
305  bool gpsValid_;
306 //#endif
307 
308  };
309 }
310 #endif
311 
bool PointValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:282
void SetPTU(DC_ptu &p)
Definition: Camera.hh:180
void SetTime(double sec)
set time from double (in seconds and useconds after full seconds)
Definition: Camera.hh:132
void GetTime(unsigned long long int &sec, unsigned long long int &usec)
Definition: Camera.hh:139
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void SetASCIIString(const std::string &ASCIIString)
Definition: Camera.hh:112
const DC_GPS & GetGPS() const
Definition: Camera.hh:188
bool TimeValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:248
BIAS::UUID const GetReferenceUUID() const
Definition: Camera.hh:223
bool PValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:258
DC_GPS gps
Definition: Camera.hh:303
extends the Image by MetaData support (e.g.
Definition: Camera.hh:74
KMatrix _K
camera calibration with internals
Definition: Camera.hh:265
bool RValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:272
const Vector3< double > & GetC() const
Definition: Camera.hh:168
bool IsCValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:213
bool IsKValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:207
double GetTime() const
Definition: Camera.hh:145
void SetOrientation(const BIAS::Vector3< double > &ori)
Definition: Camera.hh:155
void GetOrientation(float &o0, float &o1, float &o2) const
Definition: Camera.hh:160
void GetOrientation(BIAS::Vector3< double > &ori) const
Definition: Camera.hh:163
void SetOrientation(const float ori[3])
Definition: Camera.hh:151
bool gpsValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:305
Vector3< double > _C
camera center in wcs
Definition: Camera.hh:275
HomgPoint2D _Point
a point, it is up to you what you put in
Definition: Camera.hh:280
int SetP(const PMatrix &matP)
Definition: Camera.hh:102
bool IsgpsValid()
Definition: Camera.hh:229
DC_ptu ptu
Definition: Camera.hh:295
bool ASCIIValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:239
virtual Camera< StorageType > * Clone() const
virtual covariant copy constructor which produces the same type of object as the template object (Ima...
Definition: Camera.hh:88
void SetGPS(DC_GPS &g)
Definition: Camera.hh:187
3D rotation matrix
Definition: RMatrix.hh:49
bool IsTimeValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:198
bool IsinertialValid()
Definition: Camera.hh:228
DC_inertial inertial
Definition: Camera.hh:299
const double Getf() const
Definition: Camera.hh:177
std::string ASCIIString_
ASCII multifunctional string.
Definition: Camera.hh:237
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
void SetReferenceUUID(const BIAS::UUID &uid)
Definition: Camera.hh:224
const DC_inertial & GetInertial() const
Definition: Camera.hh:185
double _f
focal length in m
Definition: Camera.hh:285
unsigned long long int TimeUSec_
time stamp in microseconds
Definition: Camera.hh:246
PMatrix P_
pmatrix, maybe non-metric
Definition: Camera.hh:256
int SetProj(const Projection &Proj)
Definition: Camera.hh:106
void SetC(const Vector3< double > &C)
Definition: Camera.hh:167
bool IsPointValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:216
std::string GetASCIIString()
Definition: Camera.hh:117
bool fValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:287
class BIASVideoSource_EXPORT Camera
The image template class for specific storage types.
Definition: Image.hh:78
BIAS::UUID RefUUID_
Definition: Camera.hh:291
bool inertialValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:301
bool IsptuValid()
Definition: Camera.hh:227
void SetInertial(DC_inertial &i)
Definition: Camera.hh:183
const BIAS::PMatrix & GetP() const
Definition: Camera.hh:104
bool IsfValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:219
const DC_ptu & GetPTU() const
Definition: Camera.hh:181
Projection Proj_
Definition: Camera.hh:261
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
bool IsProjValid() const
Definition: Camera.hh:221
bool IsRValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:210
unsigned long long int TimeSec_
time stamp in seconds
Definition: Camera.hh:243
bool KValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:267
void Setf(const double &focal)
Definition: Camera.hh:176
bool IsOrientationValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:201
bool ptuValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:297
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after &#39;sec&#39;)
Definition: Camera.hh:124
bool ProjValid_
Definition: Camera.hh:262
RMatrix _R
camera orientation
Definition: Camera.hh:270
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
const RMatrix & GetR() const
Definition: Camera.hh:171
bool CValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:277
void SetK(const KMatrix &K)
Definition: Camera.hh:173
interface class for producing/storing Universally Unique IDentifiers
Definition: UUID.hh:98
bool IsPValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
Definition: Camera.hh:204
const BIAS::Projection & GetProj() const
Definition: Camera.hh:109
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
void SetR(const RMatrix &R)
Definition: Camera.hh:170
bool OrientationValid_
is correspondig field of data valid or unknown ?
Definition: Camera.hh:253
const KMatrix & GetK() const
Definition: Camera.hh:174