Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FMatrixTest.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 FMatrixTest.cpp
27  @relates FMatrix, FMatrixEstimation
28  @brief example demonstrating F-Matrix
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include "../FMatrix.hh"
34 #include "../FMatrixEstimation.hh"
35 #include "../PMatrixEstimation.hh"
36 #include "../PMatrixLinear.hh"
37 #include "../Triangulation.hh"
38 #include "../../Base/Math/Random.hh"
39 
40 
41 
42 using namespace BIAS;
43 using namespace std;
44 
45 // ---------------------------------------------------------------------------
46 //int main(int argc, char *argv[])
47 int main()
48 {
49  BIAS::FMatrix F, TheoF;
50  std::vector<FMatrix> vecF;
51  BIAS::PMatrix P1,P2;
52  BIAS::Random Randomizer;
53 
54  for (unsigned int i=0; i<1; i++) {
55  // generate random ps:
56  for (unsigned int x=0; x<4; x++)
57  for (unsigned int y=0; y<3; y++) {// mit K, R und C erzeugen
58  P1[y][x] = Randomizer.GetUniformDistributed(-1.0, 1.0);
59  P2[y][x] = Randomizer.GetUniformDistributed(-1.0, 1.0);
60  }
63  TheoF.ComputeFromPMatrices(P1, P2);
64 
65  vector<HomgPoint3D> points;
66  vector<HomgPoint2D> p1,p2;
67  cout << "Randomized correspondences are "<<endl;
68  for (unsigned int p=0; p<7; p++) {
69  points.push_back(HomgPoint3D(Randomizer.GetUniformDistributed(-1.0,
70  1.0),
71  Randomizer.GetUniformDistributed(-1.0,
72  1.0),
73  Randomizer.GetUniformDistributed(-1.0,
74  1.0)));
75  p1.push_back(P1 * points[p]); p1[p].Homogenize();
76  cout << "{ "<<p1[p]<<" ";
77  p2.push_back(P2 * points[p]); p2[p].Homogenize();
78  cout << p2[p]<<" } "<<endl;
79  }
80  bool NormalizeHartley = true;
81  FMatrixEstimation FEstimator(NormalizeHartley);
82  //vecF.resize(1);
83  vecF.clear();
84  FEstimator.SevenPoint(vecF,p1,p2);
85 
86 
87 // ground truth daten in threedout ausgeben und anzeigen(mipview3d)
88 
89 
90  // hier hat man F
91 
92  // nimm leicht falsches K an und
93 // rufe auf PMatrixEstimation::InitFromF(falschK, P1,P2, F): hier 2 funktionen! unterschied ?
94 
95 
96 // Trianguate(P1,P2, p1,p2, points3d)
97 
98 // ThreedOut::ASddPoints(points3d)
99 // threedout::AddCameras(P1,P2)
100 // threedout::vrmlout("myswcene.wrl");
101 
102 // spaeter punkte verrauschen +- 0.x pixel
103 // spaeter: selbstkalibrierung
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114  HomgPoint2D e1,e2, theoe1, theoe2;
115  cout << "Computing epipoles "<<endl;
116  TheoF.GetEpipolesHomogenized(theoe1, theoe2);
117  for (unsigned int s=0; s<vecF.size(); s++) {
118 
119  vecF[s].GetEpipolesHomogenized(e1, e2);
120  cout << "True epipoles are "<<theoe1<<" and "<<theoe2<<endl;
121  cout << "est. epipoles are "<<e1<<" and "<<e2<<endl;
122  }
123 
124  }
125  return 0;
126 }
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Definition: Random.hh:84
class representing a Fundamental matrix
Definition: FMatrix.hh:46
void InvalidateDecomposition()
to re-Decompose_() after filling with data use this.
Definition: PMatrix.hh:499
functions for estimating a fundamental matrix (FMatrix) given a set of 2d-2d correspondences (no outl...
void ComputeFromPMatrices(BIAS::PMatrix &P1, BIAS::PMatrix &P2)
computes an F matrix from two cameras (defined by arbitrary P matrices, not only metric ones) ...
Definition: FMatrix.cpp:38
void GetEpipolesHomogenized(HomgPoint2D &E1, HomgPoint2D &E2) const
same as above, additionally homogenizes epipoles
Definition: FMatrix.hh:83
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
class for producing random numbers from different distributions
Definition: Random.hh:51
class BIASGeometryBase_EXPORT HomgPoint3D