Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleProjection.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 ExampleProjection.cpp
27  @relates Projection
28  @brief Example Projection
29  @ingroup g_examples
30  @author MIP
31 */
32 #include <Geometry/Projection.hh>
33 #include <Geometry/ProjectionParametersSpherical.hh>
34 #include <iostream>
35 
36 using namespace BIAS;
37 using namespace std;
38 
39 int main (int argc, char* argv[])
40 {
41  Projection proj1, proj2;
42 #ifdef BIAS_HAVE_XML2
43  if (argc<2) {
44  cout <<"no file given, terminating!"<<endl;
45  exit(0);
46  }
47  else {
48  if (proj1.XMLRead(argv[1])<0) {
49  if (proj1.ReadFromCamParamFile(argv[1])<0) {
50  cout << "Error reading file:" << argv[1] << endl;
51  exit(0);
52  }
53  }
54  cout << "Read file:" << argv[1] << endl;
55  }
56 
57  cout <<"Projection is: "<<proj1<<endl;
59  dynamic_cast<ProjectionParametersSpherical *> (proj1.GetParameters());
60 
61  if (pps!=NULL) {
62  KMatrix K1, K2, K3;
63  double imgsize1,imgsize2, imgsize3;
64  K1 = pps->GetFakeKMatrix(imgsize1,0);
65  K2 = pps->GetFakeKMatrix(imgsize2,1);
66  K3 = pps->GetFakeKMatrix(imgsize3,2);
67  cout << "KMatNormal:" << imgsize1 << "x" << imgsize1 << K1 << endl;
68  cout << "KMatBig:" << imgsize2 << "x" << imgsize1 << K2 << endl;
69  cout << "KMatSmall:" << imgsize3 << "x" << imgsize1 << K3 << endl;
70 
71  for (int i=0; i<6; i++) {
73  Vector3<double> rpt(1.0,
74  -M_PI*double(i)*M_PI/3.0,
75  i*pps->GetMaxCamAngle()/6);
76  cout << "Creating perspective cutout " << i << " with center:"
77  << pps->ProjectLocal(rpt.CoordSphereToEuclidean()) << endl;
78  pps->GetPerspectiveCutOutParameters(pps->ProjectLocal(rpt.CoordSphereToEuclidean()), 25, pp);
79  Projection p(pp);
80  stringstream ss;
81  ss << "PerspectiveCutOut" << i << ".xml";
82  p.XMLWrite(ss.str().c_str());
83  cout << "wrote " << ss.str().c_str() << endl;
84 
85  }
86  }
87 
88  string flat;
89  proj1.XMLWriteToString(flat);
90  cout <<"My Projection flat as string: "<<flat<<endl;
91  proj1.XMLReadFromString(flat);
92  proj1.XMLWrite("PassedThroughString.xml");
93 
94 
95  cout <<"Externals: "<<proj1.GetParameters()->GetExternals()<<endl;
96  HomgPoint3D p3d;
97  HomgPoint2D p2d;
98 
99  p3d[0] = 10.0; p3d[1] = 11.0; p3d[2] = -10.0; p3d[3] = 1.0;
100 
101  p2d = proj1.Project(p3d);
102  cout <<p3d<<" -> "<<p2d<<endl;
103 
104  proj1.XMLWrite("CamDataTest.xml");
105  cout <<"CamDataTest.xml created" << endl;
106 
107  proj2.XMLRead("CamDataTest.xml");
108  proj2.XMLWrite("CamDataTestRewrite.xml");
109  cout <<"CamDataTestRewrite.xml created" << endl;
110 
111 
112 
113 
114 
115 #endif
116  return 0;
117 }
int XMLReadFromString(const std::string &str)
reconstruct xml tree from string
Definition: XMLBase.cpp:111
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
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
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual BIAS::Matrix3x4< double > GetExternals() const
Return cached 3x4 representation of external matrix [R|C].
int XMLWriteToString(std::string &str, std::string encoding="UTF-8") const
serialize xml tree to string
Definition: XMLBase.cpp:61
virtual BIAS::KMatrix GetFakeKMatrix(double &imgsize, int resolution=0, const double &maxangle=1.4) const
Returns a fake KMatrix for the fisheye camera.
virtual HomgPoint2D ProjectLocal(const Vector3< double > &point, bool IgnoreDistortion=false) const
calculates the projection of a point in the local camera coordinate system to a pixel in the image pl...
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
Definition: Projection.hh:194
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
int XMLWrite(const std::string &Filename, int CompressionLevel=0, bool AutoAddCompressionSuffix=true, std::string encoding="UTF-8") const
call this to add the class to a new xml tree and write it to the file Filename.
Definition: XMLBase.cpp:40
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
bool GetPerspectiveCutOutParameters(const BIAS::HomgPoint2D &viewCenter, const double perspHalfViewingAngleDEG, ProjectionParametersPerspective &pp) const
Calculates perspective camera with specified viewing angle and optical axis aligned with the optical ...
virtual HomgPoint2D Project(const HomgPoint3D &X, unsigned int cam=0, bool IgnoreDistortion=false) const
returns the 2d projection of X in camera cam, where X is given in the global coordinate frame (not th...
Definition: Projection.cpp:250
double GetMaxCamAngle() const
Get maximal camera angle (in rad), i.e.
int ReadFromCamParamFile(const std::string &filename, const bool silent=false)
Reads a camera data XML file and constructs the ProjectionParametersBase-pointer, using the Projectio...
Definition: Projection.cpp:99