Berkeley SfM
fundamental_matrix_ransac_problem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  * Erik Nelson ( eanelson@eecs.berkeley.edu )
36  */
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 //
40 // These classes defines the FundamentalMatrixRansacProblem API, and derive from
41 // the base RansacProblem and RansacModel class/struct.
42 //
43 ///////////////////////////////////////////////////////////////////////////////
44 
45 #ifndef BSFM_RANSAC_FUNDAMENTAL_MATRIX_RANSAC_PROBLEM_H
46 #define BSFM_RANSAC_FUNDAMENTAL_MATRIX_RANSAC_PROBLEM_H
47 
48 #include <Eigen/Dense>
49 #include <vector>
50 
51 #include "ransac_problem.h"
52 #include "../matching/feature_match.h"
53 #include "../util/disallow_copy_and_assign.h"
54 
55 namespace bsfm {
56 
57 using Eigen::Matrix3d;
58 using Eigen::Vector3d;
59 
60 // ------------ FundamentalMatrixRansacModel derived ------------ //
61 
62 struct FundamentalMatrixRansacModel : public RansacModel<FeatureMatch> {
65 
66  // Define an additional constructor specifically for this model.
67  FundamentalMatrixRansacModel(const Matrix3d& F);
68 
69  // Return model error.
70  virtual double Error() const;
71 
72  // Evaluate model on a single data element and update error.
73  virtual bool IsGoodFit(const FeatureMatch& data_point,
74  double error_tolerance);
75 
76  // Compute x1' * F_ * x2 for the input match.
77  double EvaluateEpipolarCondition(const FeatureMatch& match) const;
78 
79  // Model-specific member variables.
80  Matrix3d F_;
81  double error_;
82 }; //\struct FundamentalMatrixRansacModel
83 
84 
85 // ------------ FundamentalMatrixRansacProblem derived ------------ //
86 
88  : public RansacProblem<FeatureMatch, FundamentalMatrixRansacModel > {
89  public:
92 
93  // Subsample the data.
94  virtual std::vector<FeatureMatch> SampleData(unsigned int num_samples);
95 
96  // Return the data that was not sampled.
97  virtual std::vector<FeatureMatch> RemainingData(
98  unsigned int num_sampled_previously) const;
99 
100  // Fit a model to the provided data using the 8-point algorithm.
102  const std::vector<FeatureMatch>& input_data) const;
103 
104  private:
106 }; //\class FundamentalMatrixRansacProblem
107 
108 } //\namespace bsfm
109 
110 #endif
virtual std::vector< FeatureMatch > RemainingData(unsigned int num_sampled_previously) const
virtual std::vector< FeatureMatch > SampleData(unsigned int num_samples)
double EvaluateEpipolarCondition(const FeatureMatch &match) const
virtual bool IsGoodFit(const FeatureMatch &data_point, double error_tolerance)
Definition: camera.cpp:50
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
virtual FundamentalMatrixRansacModel FitModel(const std::vector< FeatureMatch > &input_data) const