Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMatrixTest.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 PMatrixTest.cpp
27  @relates PMatrix, PMatrixEstimation
28  @brief example investigating P-Matrix
29  @ingroup g_examples
30  @author MIP
31 */
32 #include "../FMatrix.hh"
33 #include "../FMatrixEstimation.hh"
34 #include "../PMatrixEstimation.hh"
35 #include "../PMatrixLinear.hh"
36 #include "../Triangulation.hh"
37 #include "../../Base/Math/Random.hh"
38 
39 
40 
41 #define FMATRIX_FILENAME_SUFFIX ".FMatrix"
42 #define CORRESPONDENCE_FILENAME_SUFFIX ".corresp"
43 
44 
45 using namespace BIAS;
46 using namespace std;
47 
48 // ---------------------------------------------------------------------------
49 //int main(int argc, char *argv[])
50 int main()
51 {
52  BIAS::FMatrix F;
53  BIAS::PMatrix TheoP1,TheoP2;
54  BIAS::Random Randomizer;
55  double rangle = 0;
56  for (unsigned int i=0; i<2; i++) {
57 
58  Vector3<double> RAxis(Randomizer.GetUniformDistributed(-1.0, 1.0),
59  Randomizer.GetUniformDistributed(-1.0, 1.0),
60  Randomizer.GetUniformDistributed(-1.0, 1.0));
61  RAxis.Normalize();
62  rangle = Randomizer.GetUniformDistributed(-M_PI, M_PI);
63 
64  Vector3<double> C(Randomizer.GetUniformDistributed(-20, 20),
65  Randomizer.GetUniformDistributed(-20, 20),
66  Randomizer.GetUniformDistributed(-20, 20));
67 
68  RMatrix R(RAxis, rangle);
69 
70  if (R[2][2] < 0.0) {
71  for (unsigned int y=0;y<3;y++) {
72  R[1][y] *= -1.0;
73  R[2][y] *= -1.0;
74  }
75  }
76 
77 
78  // check if opt axes "meet" in front of cams
79  if (C[0] * R[0][2] >0.0) C[0] *= -1.0;
80  if (C[1] * R[1][2] >0.0) C[1] *= -1.0;
81  C.Normalize();
82 
83  KMatrix K;
84  K.SetIdentity();
85  // K[0][0] = Randomizer.GetUniformDistributed(100,1000);
86  //K[1][1] = Randomizer.GetNormalDistributed(K[0][0], 0.1*K[0][0]);
87 
88 
89 
90  PMatrix TheoP2(K,R,C);
91 
92  // generate P1 as identity matrix
93  TheoP1.set_identity();
94  TheoP1 = K * TheoP1;
95 
96  FMatrix F(TheoP1, TheoP2);
97 
98  HomgPoint2D epi1, epi2;
99  F.GetEpipolesHomogenized(epi1, epi2);
100  cout <<"epipoles are "<<epi1<<" and "<<epi2 <<endl;
101 
102  HomgPoint3D VC1, VC2;
103  TheoP1.GetC(VC1);
104  TheoP2.GetC(VC2);
105  epi1 = TheoP1 * VC2; epi1.Homogenize();
106  epi2 = TheoP2 * VC1; epi2.Homogenize();
107  cout <<"validated epipoles are "<<epi1<<" and "<<epi2 <<endl;
108 
109 
110 
111 
112  //F = epi1.GetSkewSymmetricMatrix() * epi2.GetSkewSymmetricMatrix();
113  //cout <<"epipoles are now "<<epi1<<" and "<<epi2 <<endl;
114 
115 
116  // P matrix computation
117  BIAS::PMatrix P1,P2;
118 
120  //PEst.SetDebugLevel(BIAS_FQuasiEuklid|BIAS_FMATRIXDEBUG|BIAS_PMATRIXDEBUG);
121  double BaselineMagnitude = (i==0)?1:-1;
122 
123  PEst.ComputeFromFQuasiEuklid(F, BaselineMagnitude,P1,P2);
124  P2.Normalize();
125  cout << " TheoP2 = " << TheoP2 << endl;
126  //cout << "QuasiEu. P2 = " << P2 << endl;
127  //cout << "Diff is "<< P2-TheoP2<<endl;
128 
129  FMatrix FCheck(P1,P2);
130  FCheck.GetEpipolesHomogenized(epi1, epi2);
131  //cout <<"computed epipoles are "<<epi1<<" and "<<epi2 <<endl;
132 
133 
134  PEst.ComputeFromFDirect(F, BaselineMagnitude,P1,P2);
135  P2.Normalize();
136  cout << "Direct P2 = " << P2 << endl;
137  //cout << "Diff is "<< P2-TheoP2<<endl;
138  FCheck.ComputeFromPMatrices(P1,P2);
139  FCheck.GetEpipolesHomogenized(epi1, epi2);
140  cout <<"computed epipoles are "<<epi1<<" and "<<epi2 <<endl<<endl<<endl;
141 
142  }
143  return 0;
144 }
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint2D.hh:215
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Definition: Random.hh:84
void ComputeFromFQuasiEuklid(BIAS::FMatrix &F, double BaselineMagnitude, BIAS::PMatrix &P1, BIAS::PMatrix &P2)
given an FMatrix set P1 as identity and compute P2 to be consistent with F and P1 such that P2 is euc...
3D rotation matrix
Definition: RMatrix.hh:49
class representing a Fundamental matrix
Definition: FMatrix.hh:46
void GetEpipolesHomogenized(HomgPoint2D &E1, HomgPoint2D &E2) const
same as above, additionally homogenizes epipoles
Definition: FMatrix.hh:83
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
void set_identity()
Convert the PMatrixBase to &#39;identity&#39; matrix, overriding the Matrix3x4 method: 1 0 0 0 0 1 0 0 0 0 1 ...
Definition: PMatrixBase.hh:212
compute standard P1/P2 from F.
int ComputeFromFDirect(BIAS::FMatrix &F, const double &BaselineMagnitude, BIAS::PMatrix &P1, BIAS::PMatrix &P2)
given an FMatrix set P1 as identity and compute P2 to be consistent with F and P1 such that P2 is euc...
int GetC(Vector3< double > &C)
computes translation vector origin world coo -&gt; origin camera coo (center), uses decomposition, which is cached
Definition: PMatrix.cpp:165
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
Vector3< T > & Normalize()
normalize this vector to length 1
Definition: Vector3.hh:663
class for producing random numbers from different distributions
Definition: Random.hh:51
T Normalize()
divide this by biggest absolute entry, returns biggest entry
Definition: Matrix3x3.cpp:580
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
Definition: Matrix3x3.hh:429
void Normalize()
scale P such that optical axis (first three entries of last row) has unit length
Definition: PMatrix.hh:509