Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMatrixTest2.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 PMatrixTest2.cpp
28  @relates PMatrix
29  @brief example investigating P-Matrix
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include "../../Base/Math/Random.hh"
35 #include "../PMatrix.hh"
36 #include "../RMatrix.hh"
37 //#include "../KMatrix.hh"
38 
39 using namespace BIAS;
40 using namespace std;
41 
42 // ---------------------------------------------------------------------------
43 //int main(int argc, char *argv[])
44 int main() {
45 
46  BIAS::PMatrix P;
47  BIAS::Random Randomizer;
48 
49  unsigned int numTests = 30;
50  for (unsigned int i=0; i<numTests; i++) {
51 
52  Vector3<double> C(Randomizer.GetUniformDistributed(-200, 200),
53  Randomizer.GetUniformDistributed(-200, 200),
54  Randomizer.GetUniformDistributed(-200, 200));
55 
56  Vector3<double> RAxis(Randomizer.GetUniformDistributed(-1.0, 1.0),
57  Randomizer.GetUniformDistributed(-1.0, 1.0),
58  Randomizer.GetUniformDistributed(-1.0, 1.0));
59  RAxis.Normalize();
60  double rangle = Randomizer.GetUniformDistributed(-M_PI, M_PI);
61  RMatrix R(RAxis, rangle);
62 
63  KMatrix K;
64  K.SetIdentity();
65  K[0][0] = Randomizer.GetUniformDistributed(100, 1000);
66  K[1][1] = Randomizer.GetNormalDistributed(K[0][0], 0.1*K[0][0]);
67 
68  K.SetHx(Randomizer.GetUniformDistributed(100, 200));
69  K.SetHy(Randomizer.GetUniformDistributed(100, 200));
70 
71  K.SetSkew(Randomizer.GetUniformDistributed(-K[0][0], K[0][0]));
72  cout << "skew " << K.GetSkew() << endl;
73 // K.SetSkew(0.0);
74 
75  // check if opt axes "meet" in front of cams
76  if (C[0] * R[0][2] >0.0)
77  C[0] *= -1.0;
78  if (C[1] * R[1][2] >0.0)
79  C[1] *= -1.0;
80  C.Normalize();
81 
82  P.Compose(K, R, C);
83 
84  for(int x=0; x < 3; x++){
85  for(int y = 0; y < 4; y++){
86  P[x][y] += Randomizer.GetUniformDistributed(P[x][y]*0.1, P[x][y]*0.1);
87  }
88  }
89 
91 
92  KMatrix KEst;
93  RMatrix REst;
94  Vector3<double> CEst;
95 
96  KEst = P.GetK();
97  REst = P.GetR();
98  CEst = P.GetC();
99 
100  PMatrix PEst;
101  PEst.Compose(KEst, REst, CEst);
102  cout << "Test no " << i << " : " << ((PMatrix)(P - PEst)).IsZero(1e-12) << endl;
103 
105  KEst = PEst.GetK();
106  REst = PEst.GetR();
107  CEst = PEst.GetC();
108 
109  cout << "K " << (KMatrix)(K - KEst) << endl;
110  cout << "R " << (RMatrix)(R - REst) << endl;
111  cout << "C " << C - CEst << endl;
112 
113  }
114 
115  return 0;
116 }
void SetSkew(const KMATRIX_TYPE &val)
Definition: KMatrix.cpp:81
int GetR(Matrix3x3< double > &R)
Definition: PMatrix.cpp:204
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Definition: Random.hh:84
3D rotation matrix
Definition: RMatrix.hh:49
KMATRIX_TYPE GetSkew() const
Definition: KMatrix.cpp:80
void InvalidateDecomposition()
to re-Decompose_() after filling with data use this.
Definition: PMatrix.hh:499
class BIASGeometry_EXPORT PMatrix
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
void SetHy(const KMATRIX_TYPE &val)
Definition: KMatrix.cpp:87
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
Definition: Random.hh:71
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
void SetHx(const KMATRIX_TYPE &val)
Definition: KMatrix.cpp:84
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
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
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
Definition: Matrix3x3.hh:429
int GetK(KMatrix &K)
calibration matrix
Definition: PMatrix.cpp:220