Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMatrixEstimation.hh
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 #ifndef _PMatrixEstimation_h__
26 #define _PMatrixEstimation_h__
27 
28 #include <iostream>
29 #include <fstream>
30 #include <string>
31 
32 // BIAS:
33 #include "Base/Math/Matrix.hh"
34 #include "FMatrix.hh"
35 #include "RMatrix.hh"
36 #include "Geometry/PMatrix.hh"
37 #include "MathAlgo/Lapack.hh"
38 
39 #define BIAS_MAXNUMAUTOCALIBITERS 200
40 
41 namespace BIAS {
42 /** @class PMatrixEstimation
43  @ingroup g_estimation
44  @brief compute standard P1/P2 from F.
45  P1 is set to [ I | 0 ]. The epipole (determined by from F) tells us
46  only the direction of C2, so choose a C2 with |C2| = 1
47  @author frahm, koeser */
48 class BIASGeometry_EXPORT PMatrixEstimation : public Debug {
49 
50 public:
51  /** @brief Standard constructor does nothing */
53 
54  /** @brief Standard Destructor does nothing */
56 
57  /** @brief given an FMatrix set P1 as identity and compute P2 to be
58  consistent with F and P1 such that P2 is euclidean with nonlinear
59  estimation.*/
60  void ComputeFromFQuasiEuklid(BIAS::FMatrix &F, double BaselineMagnitude,
61  BIAS::PMatrix &P1, BIAS::PMatrix &P2);
62 
63  /** @brief given an FMatrix set P1 as identity and compute P2 to be
64  consistent with F and P1 such that P2 is euclidean with direct
65  solution of the problem
66 
67  @return 0: ok <0: if epipoles could not be extracted and
68  P computation failed */
69  int ComputeFromFDirect(BIAS::FMatrix &F, const double& BaselineMagnitude,
70  BIAS::PMatrix &P1, BIAS::PMatrix &P2);
71 
72  /** @brief given an FMatrix, width and height of the images, and the
73  2D-correspondences of two images, the Levenberg-Marquardt algorithm
74  is used to determine focal length, and the two projection matrices.
75  @author sedlazeck 04/2008
76  @return 0: ok
77  */
78  int AutoCalib(const BIAS::FMatrix &F, const int width, const int height,
79  const std::vector<BIAS::HomgPoint2D> &p1,
80  const std::vector<BIAS::HomgPoint2D> &p2,
81  BIAS::PMatrix &P1, BIAS::PMatrix &P2);
82 
83  static void ComputeRotation(BIAS::FMatrix &F, BIAS::HomgPoint2D &Epipole1,
84  BIAS::HomgPoint2D &Epipole2, BIAS::RMatrix &R);
85 
86  static void ComputeRotationCenter(BIAS::PMatrix P1, BIAS::PMatrix P2,
87  BIAS::RMatrix &R,
89 
90  /// pointer to vector of points in image1 (hack for Levenberg Marquardt)
91  std::vector<BIAS::HomgPoint2D> const *p1_;
92  /// pointer to vector of points in image2 (hack for Levenberg Marquardt)
93  std::vector<BIAS::HomgPoint2D> const *p2_;
94  /// image width (hack for Levenberg Marquardt)
95  int width_;
96  /// image height (hack for Levenberg Marquardt)
97  int height_;
98  /// remember error of PErrorFunc
99  double lastError_;
100 
101  std::vector<double> errorSum_;
102  std::vector<std::vector<double> > errorAll_;
103 
106 
107 protected:
108  /** @brief set P1 to identity,
109  set P2 to identity with last column epipole2 */
110  void InitP1P2Trans (BIAS::PMatrix &P1, BIAS::PMatrix &P2,
111  BIAS::HomgPoint2D &Epipole2);
112 
113  /** @brief given approximate P2, compute the nearest value of P2 which is
114  exactly compatible with P1 and F */
115  void FindClosestP2 (BIAS::FMatrix &F,
116  //BIAS::PMatrix &P1,
117  BIAS::PMatrix &P2,
118  Matrix3x3<double> &M2Matrix,
119  Vector<double> &C,
120  HomgPoint2D & Epipole2);
121 
122  /** @brief private function, that can determine focal length using different initial guesses for AutoCalib
123  * @author sedlazeck 04/2008
124  * */
125  int AutoCalib_(const BIAS::FMatrix &F, const long int numCorrs, BIAS::KMatrix &K, BIAS::PMatrix &P1,
126  BIAS::PMatrix &P2);
127 
128 };
129 }
130 
131 #endif
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
std::vector< std::vector< double > > errorAll_
double lastError_
remember error of PErrorFunc
3D rotation matrix
Definition: RMatrix.hh:49
std::vector< BIAS::HomgPoint2D > const * p1_
pointer to vector of points in image1 (hack for Levenberg Marquardt)
std::vector< double > errorSum_
class representing a Fundamental matrix
Definition: FMatrix.hh:46
compute standard P1/P2 from F.
std::vector< BIAS::HomgPoint2D > const * p2_
pointer to vector of points in image2 (hack for Levenberg Marquardt)
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
int width_
image width (hack for Levenberg Marquardt)
int height_
image height (hack for Levenberg Marquardt)
~PMatrixEstimation()
Standard Destructor does nothing.
BIAS::Matrix< double > globalM2_
BIAS::HomgPoint2D globalEpipole2_