Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleProjectionParametersProjective.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 /**
27  @example ExampleProjectionParametersProjective.cpp
28  @relates ProjectionParametersProjective
29  @brief small example demonstrating the ProjectionParametersProjective
30  @ingroup g_examples
31  @author sedlazeck 8/2009
32 */
33 
34 #include <Geometry/ProjectionParametersProjective.hh>
35 
36 using namespace BIAS;
37 using namespace std;
38 
39 int main(int argc, char *argv[])
40 {
42 
45  R.SetXYZ(30.0 / 180.0 * M_PI, 10.0 / 180.0 * M_PI, 20.0 / 180.0 * M_PI);
47  C[0] = 0.0;
48  C[1] = 0.0;
49  C[2] = 0.0;
50 
51  PMatrix P;
52  P.Compose(K, R, C);
53 
54  cout << "using P Matrix " << P << endl;
55 
56  ppp.SetP(P);
57 
58  ppp.SetImageSize(400, 600);
59 
60  cout << "retrieving C " << ppp.GetC() << endl;
61 
62  cout << "ostream after setting from P : ppp " << ppp << endl;
63 
64 #ifdef BIAS_HAVE_XML2
65  string fname = "ProjParProjExample01.xml";
66  int res = ppp.XMLWrite(fname);
67 
68  res = ppp.XMLRead(fname);
69  if (res!=0)
70  {
71  cerr << "error reading "<< fname << endl;
72  return -3;
73  }
74 #endif
75 
76  cout << "ostream after xml read ppp " << ppp << endl;
77 
78  // testing copy constructor
80 
81  cout << "copy constructor " << pppc << endl;
82 
83 
84 
85 
86  // project and unproject
87  HomgPoint3D point3D(3, 4, 0, 1);
88  HomgPoint2D point2D = ppp.Project(point3D);
89  HomgPoint3D point3DNew = HomgPoint3D(ppp.UnProjectToPoint(point2D, 5));
90  point3DNew.Homogenize();
91  cout << "orig 3D point " << point3D << " project/unproject " << point3DNew << endl;
92 
93 
94  // testing project with P and Project method
95  HomgPoint3D point3D1(1.5, -2.3, 4.34, 1.0);
96  HomgPoint2D point2D1 = ppp.Project(point3D1);
97  point2D1.Homogenize();
98  cout << "point2D by Project method " << point2D1 << endl;
99  point2D1 = ppp.GetP() * point3D1;
100  point2D1.Homogenize();
101  cout << "point2D by P projection " << point2D1 << endl;
102 
103 
104  return 0;
105 }
void SetP(const Matrix3x4< double > &P)
set 12 entries if projective P using a PMatrix
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
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
virtual Vector3< double > GetC() const
get projection center
virtual HomgPoint3D UnProjectToPoint(const HomgPoint2D &pos, double depth, bool IgnoreDistortion=false) const
calculates a 3D point in the global (not the rig) coordinate system, which belongs to the image posit...
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint2D.hh:215
void Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint3D.hh:308
3D rotation matrix
Definition: RMatrix.hh:49
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
12 parametric p for completely projective reconstruction scenarios, unknown focal lengths...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
virtual PMatrix GetP() const
return the complete pmatrix (internals+externals / projective) used for projection ...
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
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
HomgPoint2D Project(const HomgPoint3D &X, bool IgnoreDistortion=false) const
calculates the projection of a point in the world coordinate system to a pixel in the image plane of ...
class BIASGeometryBase_EXPORT HomgPoint3D