Berkeley SfM
feature_match.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 // These classes define a match between two image features. The FeatureMatch
41 // class contains the features themselves, while the LightFeatureMatch contains
42 // only the indices corresponding to the features in their respective images, as
43 // well as the distance computed between the two descriptors. The
44 // LightFeatureMatch class is cheaper to sort/store.
45 //
46 ///////////////////////////////////////////////////////////////////////////////
47 
48 #ifndef BSFM_MATCHING_FEATURE_MATCH_H
49 #define BSFM_MATCHING_FEATURE_MATCH_H
50 
51 #include <memory>
52 #include <vector>
53 
54 #include "feature.h"
55 
56 namespace bsfm {
57 
58 struct FeatureMatch {
59  typedef std::shared_ptr<FeatureMatch> Ptr;
60  typedef std::shared_ptr<const FeatureMatch> ConstPtr;
61 
62  // Default constructor.
64 
65  // Basic constructor
66  FeatureMatch(const Feature& feature1, const Feature& feature2)
67  : feature1_(feature1), feature2_(feature2) {}
68 
69  // The same feature in each image.
72 
73 }; //\struct FeatureMatch
74 
76  typedef std::shared_ptr<LightFeatureMatch> Ptr;
77  typedef std::shared_ptr<const LightFeatureMatch> ConstPtr;
78 
79  // Basic constructor.
80  LightFeatureMatch(int feature_index1, int feature_index2, double distance)
81  : feature_index1_(feature_index1),
82  feature_index2_(feature_index2),
83  distance_(distance) {}
84 
85  // Computed distance between the two features.
86  double distance_;
87 
88  // Index of the feature in each image.
91 
92  // A custom sorting function to find the match with the smallest distance.
93  static bool SortByDistance(const LightFeatureMatch& lhs,
94  const LightFeatureMatch& rhs) {
95  return lhs.distance_ < rhs.distance_;
96  }
97 }; //\struct LightFeatureMatch
98 
99 typedef std::vector<FeatureMatch> FeatureMatchList;
100 typedef std::vector<LightFeatureMatch> LightFeatureMatchList;
101 
102 } //\namespace bsfm
103 
104 #endif
std::shared_ptr< LightFeatureMatch > Ptr
Definition: feature_match.h:76
FeatureMatch(const Feature &feature1, const Feature &feature2)
Definition: feature_match.h:66
std::vector< LightFeatureMatch > LightFeatureMatchList
static bool SortByDistance(const LightFeatureMatch &lhs, const LightFeatureMatch &rhs)
Definition: feature_match.h:93
LightFeatureMatch(int feature_index1, int feature_index2, double distance)
Definition: feature_match.h:80
std::shared_ptr< FeatureMatch > Ptr
Definition: feature_match.h:59
Definition: camera.cpp:50
std::vector< FeatureMatch > FeatureMatchList
Definition: feature_match.h:99
std::shared_ptr< const FeatureMatch > ConstPtr
Definition: feature_match.h:60
std::shared_ptr< const LightFeatureMatch > ConstPtr
Definition: feature_match.h:77