MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
matching.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef SFM_MATCHING_HEADER
11#define SFM_MATCHING_HEADER
12
13#include <vector>
14#include <limits>
15
16#include "math/defines.h"
17#include "sfm/defines.h"
19
21
23{
24public:
51
56 struct Result
57 {
58 /* Matches from set 1 in set 2. */
59 std::vector<int> matches_1_2;
60 /* Matches from set 2 in set 1. */
61 std::vector<int> matches_2_1;
62 };
63
64public:
71 template <typename T>
72 static void
73 oneway_match (Options const& options,
74 T const* set_1, int set_1_size,
75 T const* set_2, int set_2_size,
76 std::vector<int>* result);
77
83 template <typename T>
84 static void
85 twoway_match (Options const& options,
86 T const* set_1, int set_1_size,
87 T const* set_2, int set_2_size,
88 Result* matches);
89
95 static void
96 remove_inconsistent_matches (Result* matches);
97
101 static int
102 count_consistent_matches (Result const& matches);
103
107 static void
108 combine_results(Result const& sift_result,
109 Result const& surf_result, Matching::Result* result);
110};
111
112/* ---------------------------------------------------------------- */
113
114template <typename T>
115void
116Matching::oneway_match (Options const& options,
117 T const* set_1, int set_1_size,
118 T const* set_2, int set_2_size,
119 std::vector<int>* result)
120{
121 result->clear();
122 result->resize(set_1_size, -1);
123 if (set_1_size == 0 || set_2_size == 0)
124 return;
125
126 float const square_lowe_thres = MATH_POW2(options.lowe_ratio_threshold);
127 float const square_dist_thres = MATH_POW2(options.distance_threshold);
129 nn.set_elements(set_2);
130 nn.set_num_elements(set_2_size);
132
133 for (int i = 0; i < set_1_size; ++i)
134 {
135 typename NearestNeighbor<T>::Result nn_result;
136 T const* query_pointer = set_1 + i * options.descriptor_length;
137 nn.find(query_pointer, &nn_result);
138 if (nn_result.dist_1st_best > square_dist_thres)
139 continue;
140 if (static_cast<float>(nn_result.dist_1st_best)
141 / static_cast<float>(nn_result.dist_2nd_best)
142 > square_lowe_thres)
143 continue;
144 result->at(i) = nn_result.index_1st_best;
145 }
146}
147
148template <typename T>
149void
150Matching::twoway_match (Options const& options,
151 T const* set_1, int set_1_size,
152 T const* set_2, int set_2_size,
153 Result* matches)
154{
155 Matching::oneway_match(options, set_1, set_1_size,
156 set_2, set_2_size, &matches->matches_1_2);
157 Matching::oneway_match(options, set_2, set_2_size,
158 set_1, set_1_size, &matches->matches_2_1);
159}
160
162
163#endif /* SFM_MATCHING_HEADER */
Nearest (and second nearest) neighbor search for normalized vectors.
void set_element_dimensions(int element_dimensions)
For SfM, this is the descriptor length.
void find(T const *query, Result *result) const
Find the nearest neighbor of 'query'.
void set_elements(T const *elements)
For SfM, this is the descriptor memory block.
void set_num_elements(int num_elements)
For SfM, this is the number of descriptors.
#define MATH_POW2(x)
Definition defines.h:68
#define SFM_NAMESPACE_END
Definition defines.h:14
#define SFM_NAMESPACE_BEGIN
Definition defines.h:13
Feature matching options.
Definition matching.h:30
int descriptor_length
The length of the descriptor.
Definition matching.h:34
float lowe_ratio_threshold
Requires that the ratio between the best and second best matching distance is below some threshold.
Definition matching.h:42
float distance_threshold
Does not accept matches with distances larger than this value.
Definition matching.h:49
Feature matching result reported as two lists, each with indices in the other set.
Definition matching.h:57
std::vector< int > matches_1_2
Definition matching.h:59
std::vector< int > matches_2_1
Definition matching.h:61
Unlike the naming suggests, these are square distances.