Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleTriangulate2.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 ExampleTriangulate2.cpp
28  @relates Triangulation
29  @brief example demonstrating triangulation
30  @ingroup g_examples
31  @author ischiller 10/2009
32 */
33 
34 
35 #include <Geometry/Triangulation.hh>
36 #include <Geometry/RMatrix.hh>
37 #include <Geometry/PMatrix.hh>
38 #include <Base/Geometry/KMatrix.hh>
39 
40 #include <fstream>
41 #include <iostream>
42 
43 using namespace BIAS;
44 using namespace std;
45 
46 //int main(int argc, char *argv[])
47 int main()
48 {
49  PMatrix
50 // pleft("415.692215 2.8e-05 320 -0
51 // 0 415.692207 239.999964 -0
52 // 0 0 1 -0"),
53 // pright("415.692215 2.8e-05 320 -443.520012
54 // 0 415.692207 239.999964 -332.640009
55 // 0 0 1 -1.386");
56  pleft("415.692177 2.7975296e-05 320 -0\
57  0 415.692207 239.9999637 -0\
58  0 8.74228e-08 1 -0 "),
59  pright("415.692177 2.7975296e-05 320 -633.6\
60  0 415.692207 239.9999637 -475.199928\
61  0 8.74228e-08 1 -1.98");
62  //HomgPoint2D point2d_im1(378.0, 86.0, 1.0), point2d_im2(379.0, 83.0, 1.0);
63  HomgPoint2D point2d_im1(407.0, 100.0, 1.0), point2d_im2(419.0, 90.0, 1.0);
64  HomgPoint2D ptl, ptr;
65  //HomgPoint3D p3, p3d_real(11.40732193, -30.37988853, 81.99732971);
66  HomgPoint3D p3, p3d_real(5.087403297, -8.891034126, 26.40314484);
67  Vector3<double> eucl3d;
69  double dist, angle;
70  Triangulation triangulator;
71  cerr <<"projecting "<<p3d_real<<" with pleft and pright: "<<endl;
72  ptl = pleft * p3d_real;
73  ptl.Homogenize();
74  cerr << "left: "<< ptl << endl;
75 
76  ptr = pright * p3d_real;
77  ptr.Homogenize();
78  cerr << "right: "<< ptr << endl;
79 
80  cerr <<endl<< "triangulating from \n"<<point2d_im1<<"\nP: "<<pleft<<endl
81  <<point2d_im2<<"\nP: "<<pright<<endl;
82  if (triangulator.Triangulate2D(pleft, pright, point2d_im1, point2d_im2,
83  p3, cov, dist, angle)!=0){
84  cerr << "error triangulating using GetNormRayWorldCoo"<<endl;
85  } else {
86  cerr << "triangulated: "<<p3<<"\n with covariance matrix: "<<cov
87  <<"\ndistance: "<<dist<<"\tangle: "<<angle<<endl;
88  }
89 
90  cerr <<endl<< "triangulating with svd from points \n"<<point2d_im1<<"\nP: "
91  <<pleft<<endl<<point2d_im2<<"\nP: "<<pright<<endl;
92  if (triangulator.Triangulate(pleft, pright, point2d_im1, point2d_im2,
93  eucl3d)!=0){
94  p3.Set(eucl3d);
95  cerr << "error triangulating using GetNormRayWorldCoo"<<endl;
96  } else {
97  p3.Set(eucl3d);
98  cerr << "triangulated: "<<p3<<endl;
99  }
100 
101 
102  cerr <<endl<<"triangulating from theoretical points \n"<<ptl<<"\nP: "
103  <<pleft<<endl <<point2d_im2<<"\nP: "<<ptr<<endl;
104  if (triangulator.Triangulate2D(pleft, pright, ptl, ptr,
105  p3, cov, dist, angle)!=0){
106  cerr << "error triangulating using GetNormRayWorldCoo"<<endl;
107  } else {
108  cerr << "triangulated: "<<p3<<"\n with covariance matrix: "<<cov
109  <<"\ndistance: "<<dist<<"\tangle: "<<angle<<endl;
110  }
111 
112 
113  return 0;
114 }
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void Set(const HOMGPOINT3D_TYPE &x, const HOMGPOINT3D_TYPE &y, const HOMGPOINT3D_TYPE &z)
set elementwise with given 3 euclidean scalar values.
Definition: HomgPoint3D.hh:321
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint2D.hh:215
int Triangulate2D(PMatrix &P1, PMatrix &P2, HomgPoint2D &p1, HomgPoint2D &p2, HomgPoint3D &point3d, double &dist, double &angle)
does not use BackprojectPseudoInverse but get NormRayWorldCoo
Class for triangulation of 3Dpoints from 2D matches. Covariance matrix (refering to an uncertainty el...
int Triangulate(PMatrix &P1, PMatrix &P2, const HomgPoint2D &p1, const HomgPoint2D &p2, BIAS::Vector3< double > &point3d)
Triangulation for metric PMatrices (using C and Hinf)
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88