Berkeley SfM
feature_matcher.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: Erik Nelson ( eanelson@eecs.berkeley.edu )
35  * David Fridovich-Keil ( dfk@eecs.berkeley.edu )
36  */
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 //
40 // This class defines a base class for feature matching. A derived class should
41 // be used to implement the specific feature matching strategy. All matching
42 // strategies will attempt to do pairwise matches between all pairs of input
43 // images. This is slow, with O(n^2) in the number of images.
44 //
45 ///////////////////////////////////////////////////////////////////////////////
46 
47 #ifndef BSFM_MATCHING_FEATURE_MATCHER_H
48 #define BSFM_MATCHING_FEATURE_MATCHER_H
49 #include <unordered_map>
50 
51 #include <glog/logging.h>
52 
53 #include "distance_metric.h"
54 #include "feature.h"
56 #include "pairwise_image_match.h"
57 
58 #include "../image/image.h"
59 #include "../util/disallow_copy_and_assign.h"
60 #include "../util/types.h"
61 
62 namespace bsfm {
63 
65  public:
67  virtual ~FeatureMatcher() { }
68 
69  // Add a single image's features for matching.
70  virtual void AddImageFeatures(
71  const std::vector<Feature>& image_features,
72  const std::vector<Descriptor>& image_descriptors);
73 
74  // Add features from a set of images for matching.
75  virtual void AddImageFeatures(
76  const std::vector<std::vector<Feature> >& image_features,
77  const std::vector<std::vector<Descriptor> >& image_descriptors);
78 
79  // Match images together using the input options.
80  virtual bool MatchImages(const FeatureMatcherOptions& options,
81  PairwiseImageMatchList& image_matches);
82 
83  protected:
84  // Abstract method to match a pair of images using the input options. Override
85  // this in the derived feature matching strategy class to implement it.
86  virtual bool MatchImagePair(int image_index1, int image_index2,
87  PairwiseImageMatch& image_match) = 0;
88 
89  // Find the set intersection of the two sets of input feature matches, and
90  // store that set in the second argument.
91  virtual void SymmetricMatches(
92  const std::vector<LightFeatureMatch>& feature_matches_lhs,
93  std::vector<LightFeatureMatch>& feature_matches_rhs);
94 
95  // Each image has a list of features and descriptors (one per feature).
96  std::vector<std::vector<Feature> > image_features_;
97  std::vector<std::vector<Descriptor> > image_descriptors_;
98 
99  // A set of options used for matching features and images.
101 
102  private:
104 
105 }; //\class FeatureMatcher
106 
107 } //\namespace bsfm
108 #endif
virtual bool MatchImages(const FeatureMatcherOptions &options, PairwiseImageMatchList &image_matches)
virtual void SymmetricMatches(const std::vector< LightFeatureMatch > &feature_matches_lhs, std::vector< LightFeatureMatch > &feature_matches_rhs)
std::vector< std::vector< Feature > > image_features_
virtual bool MatchImagePair(int image_index1, int image_index2, PairwiseImageMatch &image_match)=0
std::vector< PairwiseImageMatch > PairwiseImageMatchList
virtual void AddImageFeatures(const std::vector< Feature > &image_features, const std::vector< Descriptor > &image_descriptors)
Definition: camera.cpp:50
std::vector< std::vector< Descriptor > > image_descriptors_
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
FeatureMatcherOptions options_