Berkeley SfM
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
bsfm::FeatureMatcher Class Referenceabstract

#include <feature_matcher.h>

Inheritance diagram for bsfm::FeatureMatcher:
bsfm::NaiveMatcher2D2D

Public Member Functions

 FeatureMatcher ()
 
virtual ~FeatureMatcher ()
 
virtual void AddImageFeatures (const std::vector< Feature > &image_features, const std::vector< Descriptor > &image_descriptors)
 
virtual void AddImageFeatures (const std::vector< std::vector< Feature > > &image_features, const std::vector< std::vector< Descriptor > > &image_descriptors)
 
virtual bool MatchImages (const FeatureMatcherOptions &options, PairwiseImageMatchList &image_matches)
 

Protected Member Functions

virtual bool MatchImagePair (int image_index1, int image_index2, PairwiseImageMatch &image_match)=0
 
virtual void SymmetricMatches (const std::vector< LightFeatureMatch > &feature_matches_lhs, std::vector< LightFeatureMatch > &feature_matches_rhs)
 

Protected Attributes

std::vector< std::vector< Feature > > image_features_
 
std::vector< std::vector< Descriptor > > image_descriptors_
 
FeatureMatcherOptions options_
 

Detailed Description

Definition at line 64 of file feature_matcher.h.

Constructor & Destructor Documentation

bsfm::FeatureMatcher::FeatureMatcher ( )
inline

Definition at line 66 of file feature_matcher.h.

66 { }
virtual bsfm::FeatureMatcher::~FeatureMatcher ( )
inlinevirtual

Definition at line 67 of file feature_matcher.h.

67 { }

Member Function Documentation

void bsfm::FeatureMatcher::AddImageFeatures ( const std::vector< Feature > &  image_features,
const std::vector< Descriptor > &  image_descriptors 
)
virtual

Definition at line 43 of file feature_matcher.cpp.

45  {
46  image_features_.push_back(image_features);
47  image_descriptors_.push_back(image_descriptors);
48 }
std::vector< std::vector< Feature > > image_features_
std::vector< std::vector< Descriptor > > image_descriptors_
void bsfm::FeatureMatcher::AddImageFeatures ( const std::vector< std::vector< Feature > > &  image_features,
const std::vector< std::vector< Descriptor > > &  image_descriptors 
)
virtual

Definition at line 51 of file feature_matcher.cpp.

53  {
54  image_features_.insert(image_features_.end(), image_features.begin(),
55  image_features.end());
56  image_descriptors_.insert(image_descriptors_.end(), image_descriptors.begin(),
57  image_descriptors.end());
58 }
std::vector< std::vector< Feature > > image_features_
std::vector< std::vector< Descriptor > > image_descriptors_
virtual bool bsfm::FeatureMatcher::MatchImagePair ( int  image_index1,
int  image_index2,
PairwiseImageMatch image_match 
)
protectedpure virtual

Implemented in bsfm::NaiveMatcher2D2D.

bool bsfm::FeatureMatcher::MatchImages ( const FeatureMatcherOptions options,
PairwiseImageMatchList image_matches 
)
virtual

Definition at line 60 of file feature_matcher.cpp.

61  {
62  // Store the matching options locally.
63  options_ = options;
64 
65  // Iterate over all pairs of images and attempt to match them together by
66  // comparing their features.
67  for (size_t ii = 0; ii < image_features_.size(); ++ii) {
68  // Make sure this image has features.
69  if (image_features_[ii].size() == 0) {
70  continue;
71  }
72  for (size_t jj = ii + 1; jj < image_features_.size(); ++jj) {
73  // Make sure this image has features.
74  if (image_features_[jj].size() == 0) {
75  continue;
76  }
77 
78  // Create an image match object and attempt to match image ii to image jj.
79  PairwiseImageMatch image_match;
80  if (!MatchImagePair(ii, jj, image_match)) {
81  VLOG(1) << "Could not match image " << ii << " to image " << jj << ".";
82  continue;
83  }
84 
85  // If the image match was successful, store it.
86  image_matches.push_back(image_match);
87  }
88  }
89 
90  // Return whether or not we found matches between any of the images.
91  return image_matches.size() > 0;
92 }
std::vector< std::vector< Feature > > image_features_
virtual bool MatchImagePair(int image_index1, int image_index2, PairwiseImageMatch &image_match)=0
FeatureMatcherOptions options_
void bsfm::FeatureMatcher::SymmetricMatches ( const std::vector< LightFeatureMatch > &  feature_matches_lhs,
std::vector< LightFeatureMatch > &  feature_matches_rhs 
)
protectedvirtual

Definition at line 94 of file feature_matcher.cpp.

96  {
97  std::unordered_map<int, int> feature_indices;
98  feature_indices.reserve(feature_matches_lhs.size());
99 
100  // Add all LHS matches to the map.
101  for (const auto& feature_match : feature_matches_lhs) {
102  feature_indices.insert(std::make_pair(feature_match.feature_index1_,
103  feature_match.feature_index2_));
104  }
105 
106  // For each match in the RHS set, search for the same match in the LHS set.
107  // If the match is not symmetric, remove it from the RHS set.
108  auto rhs_iter = feature_matches_rhs.begin();
109  while (rhs_iter != feature_matches_rhs.end()) {
110  const auto& lhs_matched_iter =
111  feature_indices.find(rhs_iter->feature_index2_);
112 
113  // If a symmetric match is found, keep it in the RHS set.
114  if (lhs_matched_iter != feature_indices.end()) {
115  if (lhs_matched_iter->second == rhs_iter->feature_index1_) {
116  ++rhs_iter;
117  continue;
118  }
119  }
120 
121  // Remove the non-symmetric match and continue on.
122  feature_matches_rhs.erase(rhs_iter);
123  }
124 }

Member Data Documentation

std::vector<std::vector<Descriptor> > bsfm::FeatureMatcher::image_descriptors_
protected

Definition at line 97 of file feature_matcher.h.

std::vector<std::vector<Feature> > bsfm::FeatureMatcher::image_features_
protected

Definition at line 96 of file feature_matcher.h.

FeatureMatcherOptions bsfm::FeatureMatcher::options_
protected

Definition at line 100 of file feature_matcher.h.


The documentation for this class was generated from the following files: