Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FMatrixEstimation.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 _FMatrixEstimation_h__
26 #define _FMatrixEstimation_h__
27 
28 #include <Base/Common/BIASpragmaStart.hh>
29 
30 #include <vector>
31 #include "FMatrix.hh"
32 #include "Base/Geometry/HomgPoint2D.hh"
33 #include "MathAlgo/PolynomialSolve.hh"
34 #include "Base/Math/Vector.hh"
35 #include "Base/Geometry/Normalization.hh"
36 #include "Parametrization.hh"
37 
38 namespace BIAS {
39 /** @class FMatrixEstimation
40  @ingroup g_estimation
41  @brief functions for estimating a fundamental matrix (FMatrix) given
42  a set of 2d-2d correspondences (no outlier checks, not robust !)
43  in two views
44  @author koeser 11/2003
45  */
46 class BIASGeometry_EXPORT FMatrixEstimation : public Debug {
47 public:
48 
49  /** @brief constructor with general parameters
50  @param NormalizeHartley do hartley normalization on 7/8 points */
51  explicit inline FMatrixEstimation(bool NormalizeHartley = true) {
52  NormalizeHartley_ = NormalizeHartley;
53  }
54 
55  /** @brief compute a vector of FMatrices from seven point correspondences
56 
57  Depending on the setting of the 3d points and the cameras of the
58  originating epipolar geometry a vector of no, one or three solutions
59  is computed:
60  - degenrate case: no solution
61  - 3d points and cam centers all lie on a ruled quadric: 3 solutions
62  - 3d points and cam centers all lie on an unruled quadric: 1 solution
63 
64  @attention For robust computation it is strongly recommended that you
65  normalize your correspondences (e.g. "Hartley")
66  @param Fvec (output) vector of F matrices which are computed
67  @param p1 (homogenized!) points in image 1
68  @param p2 corresponding (homogenized!) points in image 2
69  @return 0=success, !=0: error
70  @status tested, not-optimized
71  @author koeser 11/2003 */
72  int SevenPoint(std::vector<BIAS::FMatrix>& Fvec,
73  const std::vector<BIAS::HomgPoint2D> &p1,
74  const std::vector<BIAS::HomgPoint2D> &p2);
75 
76  /** @brief compute an FMatrix from more than seven point correspondences
77 
78  This algorithm computes a least squares F on all point correspondences
79  using SVD of a model matrix. Rank 2 is enforced afterwards.
80  @attention For robust computation it is strongly recommended that you
81  normalize your correspondences (e.g. "Hartley")
82  @param F matrix which is computed
83  @param p1 (homogenized!) points in image 1
84  @param p2 corresponding (homogenized!) points in image 2
85  @return 0=success, !=0: error
86  @author koeser 11/2003 */
87  int Linear(BIAS::FMatrix& F,
88  const std::vector<BIAS::HomgPoint2D> &p1,
89  const std::vector<BIAS::HomgPoint2D> &p2);
90 
91  /** @brief compute an FMatrix from eight point correspondences
92 
93  This algorithm computes a least squares F on all point correspondences
94  using SVD of a model matrix. Rank 2 is enforced afterwards, therefore
95  @attention For robust computation it is strongly recommended that you
96  normalize your correspondences (e.g. "Hartley")
97  @param F matrix which is computed
98  @param p1 (homogenized!) points in image 1
99  @param p2 corresponding (homogenized!) points in image 2
100  @return 0=success, !=0: error
101  @author koeser 11/2003 */
102  inline int EightPoint(BIAS::FMatrix& F,
103  const std::vector<BIAS::HomgPoint2D> &p1,
104  const std::vector<BIAS::HomgPoint2D> &p2)
105  { return Linear(F, p1, p2);};
106 
107  /** @brief optimize a given FMatrix regarding n 2d point correspondences
108 
109  minimize an error function on F matrix using iterative
110  nonlinear optimization techniques such as Levenberg/Marquardt
111  @attention susceptable to local minima, provide good starting point F
112  @param F matrix which is optimized
113  @param p1 (homogenized!) points in image 1
114  @param p2 corresponding (homogenized!) points in image 2
115  @return 0=success, !=0: error
116  @author koeser 11/2003 */
117  int Optimize(BIAS::FMatrix& F,
118  const std::vector<BIAS::HomgPoint2D> &p1,
119  const std::vector<BIAS::HomgPoint2D> &p2);
120 
121  /** @brief Compute FMatrix using the Gold Standard algorithm as in
122  * Hartley and Zisserman p. 285
123  * @param F matrix which is calculated
124  * @param p1 (homogenized points in image1
125  * @param p2 corresponding (homogenized!) points in image 2
126  * @return 0=success, !=0: error
127  * @author sedlazeck 04/2008
128  */
129  int GoldStandard(BIAS::FMatrix& F,
130  const std::vector<BIAS::HomgPoint2D> &p1,
131  const std::vector<BIAS::HomgPoint2D> &p2);
132 
133  /** @brief enforces a maximum rank of two by setting the smallest singular
134  value to zero
135 
136  @param F matrix which has rank MIN{2, previous_rank} afterwards
137  @author koeser 11/2003 */
138  void EnforceMaxRank2(BIAS::FMatrix &F);
139 
140  /// pointer to vector of points in image1 (hack for Optimize)
141  std::vector<BIAS::HomgPoint2D> const *p1_;
142  /// pointer to vector of points in image2 (hack for Optimize)
143  std::vector<BIAS::HomgPoint2D> const *p2_;
144  /// count Levenberg-Marquardt iterations
145  int itersLM_;
146 
147 
148  /** @brief set up a polynomial in alpha given Det(alpha*F1+(1-alpha)*F2)=0,
149  where the f vectors are interpreted as the rows of a 3x3 matrix
150 
151  @param f1 vector to be interpreted as a 3x3 matrix F1
152  @param f2 vector to be interpreted as a 3x3 matrix F2
153  @param v vector of polynomial coefficients in PolynomialSolve style
154  @author koeser 11/2003 */
155  void GetDetPolynomial(const BIAS::Vector<double> &f1,
156  const BIAS::Vector<double> &f2,
157  std::vector<POLYNOMIALSOLVE_TYPE> &v);
158 
159 
160  void ComputeNormFParam(const BIAS::FMatrix& initialF, BIAS::FMatrix& normF);
161 
162  /// matrix for saving normalization of 2D points - important for f parametrization
164  /// matrix for saving normalization of 2D points - important for f parametrization
166 
168 
169 protected:
170  /// flag indicating whether we should normalize the given points before
171  /// and denormalize the fmatrix after computation, so that it refers to
172  /// the original points
174 
175  /// the normalization object
177 
178 }; // end class
179 
180 }
181 // end namespace
182 
183 #include <Base/Common/BIASpragmaEnd.hh>
184 
185 #endif
std::vector< BIAS::HomgPoint2D > const * p2_
pointer to vector of points in image2 (hack for Optimize)
This class is used for parametrizing F- and H-matrices, generally for optimization purposes...
std::vector< BIAS::HomgPoint2D > const * p1_
pointer to vector of points in image1 (hack for Optimize)
BIAS::Parametrization * currentPara_
bool NormalizeHartley_
flag indicating whether we should normalize the given points before and denormalize the fmatrix after...
Matrix3x3< double > NormF2_
matrix for saving normalization of 2D points - important for f parametrization
class representing a Fundamental matrix
Definition: FMatrix.hh:46
functions for estimating a fundamental matrix (FMatrix) given a set of 2d-2d correspondences (no outl...
class Normalization Functions, e.g.
FMatrixEstimation(bool NormalizeHartley=true)
constructor with general parameters
int itersLM_
count Levenberg-Marquardt iterations
int EightPoint(BIAS::FMatrix &F, const std::vector< BIAS::HomgPoint2D > &p1, const std::vector< BIAS::HomgPoint2D > &p2)
compute an FMatrix from eight point correspondences
Matrix3x3< double > NormF1_
matrix for saving normalization of 2D points - important for f parametrization
Normalization N_
the normalization object