Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCamera.cpp
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  @example ExampleCamera.cpp
27  @relates Camera
28  @brief Example for camera object using, BIAS::Camera is an enhanced BIAS::Image with Metadata
29  @ingroup g_examples
30  @author MIP
31 */
32 // must be first:
33 //#include <Base/Common/LeakChecking.h>
34 
35 #include "Image/Camera.hh"
36 #include "Base/Image/ImageIO.hh"
37 
38 using namespace BIAS;
39 using namespace std;
40 
41 
42 int main(int argc, char *argv[])
43 {
44  Camera<unsigned char> cam, cam2, cam3;
45  PMatrix P;
46  KMatrix K;
47  RMatrix R;
48  Projection proj;
49  R.SetXYZ(0.0, 0.0, 0.0);
50  Vector3<double> C(1.0, 2.0, 3.0);
51  BIAS::UUID UID;
52 
53  cam.Init(640, 480, 1);
54  cam.FillImageWithXValue();
55 
56  // check if DAIMLER format is used
57  if (argc>2) {
58  const std::string format(argv[2]);
59  if (format.compare("--daimler") == 0 ||
60  format.compare("-daimler") == 0)
61  {
62  DC_ptu ptu;
63  DC_inertial inert;
64  DC_GPS gps;
65 
66  ptu.PanPos=1;
67  ptu.TiltPos=0.56;
68  ptu.TimeStamp=1234567890;
69 
70  inert.Set(1.0, 2.0, 3.14, 4.2, 7.2);
71 
72  gps.Set(7, 1.5, 2.5, 3.5, 4.5, 5.5);
73 
74  cam.SetPTU(ptu);
75  cam.SetInertial(inert);
76  cam.SetGPS(gps);
77  } else {
78  cout << "Use --daimler as second argument to use Daimler camera format." << endl;
79  return 0;
80  }
81  }
82 
83  K.SetIdentity();
84  K[0][0]=K[1][1]=100;
85  K[0][2]=cam.GetWidth()/2.0;
86  K[1][2]=cam.GetHeight()/2.0;
87  P.Compose(K, R, C);
88 
89  if (argc>1) {
90  cout <<"Reading projection from "<<argv[1]<<endl;
91  proj.XMLRead(argv[1]);
92  cam.SetProj(proj);
93  }
94  cam.SetP(P);
95  cam.SetC(C);
96  cam.SetR(R);
97  cam.SetK(K);
98  cam.Setf(0.008); // focal length 8mm
100 
101  cam.UpdateMetaData();
102 
103  cout <<endl<< "added meta data to camera: "<<endl;
104  //cam.PrintAppData(cout);
105  cam.GetMetaData()->Dump();
106 
107  //if (ImageIO::Save("cam", cam)!=0){
108  if (ImageIO::Save("cam", cam)!=0){
109  BIASERR("error writing cam.mip");
110  return -1;
111  }
112 
113  //if (ImageIO::Load("cam.mip", cam2)!=0){
114  if (ImageIO::Load("cam.mip", cam2)!=0){
115  BIASERR("error reading cam.mip");
116  return -1;
117  }
118 
119  cam2.ParseMetaData();
120 
121  cout <<endl<< "====== now read from mip: \nC:\n" << cam2.GetC()
122  << "\nR:\n"<<cam2.GetR()<<"\nK:\n"<<cam2.GetK()
123  << "\nP:\n"<<cam2.GetP()<<" Projection: "<< cam2.GetProj()<<endl;
124  cout <<"==== PrintAppData() from mip ======="<<endl;
125  cam.PrintAppData(cout);
126  cerr << "sizeof metadata: "<<cam.GetMetaData()->size()<<endl;
127  if (ImageIO::Save("cam", cam, ImageIO::FF_pgm)!=0){
128  BIASERR("error writing cam.pgm");
129  return -1;
130  }
131 
132  if (ImageIO::ImportImage("cam.pgm", cam3)!=0){
133  BIASERR("error reading cam.pgm");
134  return -1;
135  }
136  cout <<endl<< "now read from pgm:"<<endl;
137  cam3.SetDebugLevel(cam3.GetDebugLevel() |D_CAMERA_METADATA );
138  cam3.ParseMetaData();
139  cam3.GetMetaData()->Dump();
140  cout <<"My Projection fom pgm: "<< cam3.GetProj()<<endl;
141 
142  return 0;
143 }
void SetPTU(DC_ptu &p)
Definition: Camera.hh:180
static int ImportImage(const std::string &filename, ImageBase &result)
Try to load/import an image from a file using external libs.
Definition: ImageIO.cpp:378
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
void Set(double yaw, double yawrateraw, double yawrateoffset, double speed, double steeringangle)
Definition: DCData.cpp:212
int XMLRead(const std::string &Filename)
derived classes must implement the function XMLIn which is called by this function XMLRead to read ev...
Definition: XMLBase.cpp:78
const Vector3< double > & GetC() const
Definition: Camera.hh:168
MetaData * GetMetaData()
Definition: ImageBase.hh:456
int SetP(const PMatrix &matP)
Definition: Camera.hh:102
unsigned int GetWidth() const
Definition: ImageBase.hh:312
double TiltPos
Definition: DCData.hh:57
void SetGPS(DC_GPS &g)
Definition: Camera.hh:187
int GetDebugLevel() const
Definition: Debug.hh:332
void Set(int framenum, double latPos, double longPos, double azimuth, double speed, double distanceToMap)
Definition: DCData.cpp:439
3D rotation matrix
Definition: RMatrix.hh:49
unsigned int TimeStamp
Definition: DCData.hh:58
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
int SetProj(const Projection &Proj)
Definition: Camera.hh:106
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
unsigned int GetHeight() const
Definition: ImageBase.hh:319
void FillImageWithXValue()
fills image with value depending on x coordinate
Definition: Image.cpp:608
void SetC(const Vector3< double > &C)
Definition: Camera.hh:167
double PanPos
Definition: DCData.hh:57
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
void SetInertial(DC_inertial &i)
Definition: Camera.hh:183
const BIAS::PMatrix & GetP() const
Definition: Camera.hh:104
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
int UpdateMetaData()
copy P_ and co.
Definition: Camera.cpp:446
void PrintAppData(std::ostream &os)
see whats in the camera, for debug
Definition: Camera.cpp:87
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
void Setf(const double &focal)
Definition: Camera.hh:176
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
const RMatrix & GetR() const
Definition: Camera.hh:171
void SetK(const KMatrix &K)
Definition: Camera.hh:173
interface class for producing/storing Universally Unique IDentifiers
Definition: UUID.hh:98
const BIAS::Projection & GetProj() const
Definition: Camera.hh:109
void SetR(const RMatrix &R)
Definition: Camera.hh:170
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
Definition: Camera.cpp:154
static UUID GenerateUUID(const bool &consecutively=DEFAULT_UUID_CONSECUTIVELY)
static function which simply produces a uuid and returns
Definition: UUID.cpp:235
void Dump(std::ostream &os=std::cout)
dumps this to cout, unfinished piece of code
Definition: MetaData.cpp:460
const KMatrix & GetK() const
Definition: Camera.hh:174
void Compose(const Matrix3x3< double > &K, const Matrix3x3< double > &R, const Vector3< double > &C)
composes this from K, R and C using P = [ K R&#39; | -K R&#39; C ] with R&#39; = transpose(R) ...
Definition: PMatrix.cpp:581
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
Definition: Matrix3x3.hh:429