MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
exhaustive_matching.cc
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
11
13
14namespace
15{
16#if DISCRETIZE_DESCRIPTORS
17 void
18 convert_descriptor (Sift::Descriptor const& descr, unsigned short* data)
19 {
20 for (int i = 0; i < 128; ++i)
21 {
22 float value = descr.data[i];
23 value = math::clamp(value, 0.0f, 1.0f);
24 value = math::round(value * 255.0f);
25 data[i] = static_cast<unsigned char>(value);
26 }
27 }
28
29 void
30 convert_descriptor (Surf::Descriptor const& descr, signed short* data)
31 {
32 for (int i = 0; i < 64; ++i)
33 {
34 float value = descr.data[i];
35 value = math::clamp(value, -1.0f, 1.0f);
36 value = math::round(value * 127.0f);
37 data[i] = static_cast<signed char>(value);
38 }
39 }
40#else // DISCRETIZE_DESCRIPTORS
41 void
42 convert_descriptor (Sift::Descriptor const& descr, float* data)
43 {
44 std::copy(descr.data.begin(), descr.data.end(), data);
45 }
46
47 void
48 convert_descriptor (Surf::Descriptor const& descr, float* data)
49 {
50 std::copy(descr.data.begin(), descr.data.end(), data);
51 }
52#endif // DISCRETIZE_DESCRIPTORS
53}
54
55void
56ExhaustiveMatching::init (bundler::ViewportList* viewports)
57{
58 this->processed_feature_sets.clear();
59 this->processed_feature_sets.resize(viewports->size());
60
61#pragma omp parallel for schedule(dynamic)
62 for (size_t i = 0; i < viewports->size(); i++)
63 {
64 FeatureSet const& fs = (*viewports)[i].features;
65 ProcessedFeatureSet& pfs = this->processed_feature_sets[i];
66
67 this->init_sift(&pfs.sift_descr, fs.sift_descriptors);
68 this->init_surf(&pfs.surf_descr, fs.surf_descriptors);
69 }
70}
71
72void
73ExhaustiveMatching::init_sift (SiftDescriptors* dst,
74 Sift::Descriptors const& src)
75{
76 /* Prepare and copy to data structures. */
77 dst->resize(src.size());
78
79#if DISCRETIZE_DESCRIPTORS
80 uint16_t* ptr = dst->data()->begin();
81#else
82 float* ptr = dst->data()->begin();
83#endif
84 for (std::size_t i = 0; i < src.size(); ++i, ptr += 128)
85 {
86 Sift::Descriptor const& d = src[i];
87 convert_descriptor(d, ptr);
88 }
89}
90
91void
92ExhaustiveMatching::init_surf (SurfDescriptors* dst,
93 Surf::Descriptors const& src)
94{
95 /* Prepare and copy to data structures. */
96 dst->resize(src.size());
97
98#if DISCRETIZE_DESCRIPTORS
99 int16_t* ptr = dst->data()->begin();
100#else
101 float* ptr = dst->data()->begin();
102#endif
103 for (std::size_t i = 0; i < src.size(); ++i, ptr += 64)
104 {
105 Surf::Descriptor const& d = src[i];
106 convert_descriptor(d, ptr);
107 }
108}
109
110void
111ExhaustiveMatching::pairwise_match (int view_1_id, int view_2_id,
112 Matching::Result* result) const
113{
114 ProcessedFeatureSet const& pfs_1 = this->processed_feature_sets[view_1_id];
115 ProcessedFeatureSet const& pfs_2 = this->processed_feature_sets[view_2_id];
116
117 /* SIFT matching. */
118 Matching::Result sift_result;
119 if (pfs_1.sift_descr.size() > 0)
120 {
121 Matching::twoway_match(this->opts.sift_matching_opts,
122 pfs_1.sift_descr.data()->begin(), pfs_1.sift_descr.size(),
123 pfs_2.sift_descr.data()->begin(), pfs_2.sift_descr.size(),
124 &sift_result);
125 Matching::remove_inconsistent_matches(&sift_result);
126 }
127
128 /* SURF matching. */
129 Matching::Result surf_result;
130 if (pfs_1.surf_descr.size() > 0)
131 {
132 Matching::twoway_match(this->opts.surf_matching_opts,
133 pfs_1.surf_descr.data()->begin(), pfs_1.surf_descr.size(),
134 pfs_2.surf_descr.data()->begin(), pfs_2.surf_descr.size(),
135 &surf_result);
136 Matching::remove_inconsistent_matches(&surf_result);
137 }
138
139 Matching::combine_results(sift_result, surf_result, result);
140}
141
142int
143ExhaustiveMatching::pairwise_match_lowres (int view_1_id, int view_2_id,
144 std::size_t num_features) const
145{
146 ProcessedFeatureSet const& pfs_1 = this->processed_feature_sets[view_1_id];
147 ProcessedFeatureSet const& pfs_2 = this->processed_feature_sets[view_2_id];
148
149 /* SIFT lowres matching. */
150 if (pfs_1.sift_descr.size() > 0)
151 {
152 Matching::Result sift_result;
153 Matching::twoway_match(this->opts.sift_matching_opts,
154 pfs_1.sift_descr.data()->begin(),
155 std::min(num_features, pfs_1.sift_descr.size()),
156 pfs_2.sift_descr.data()->begin(),
157 std::min(num_features, pfs_2.sift_descr.size()),
158 &sift_result);
159 return Matching::count_consistent_matches(sift_result);
160 }
161
162 /* SURF lowres matching. */
163 if (pfs_1.surf_descr.size() > 0)
164 {
165 Matching::Result surf_result;
166 Matching::twoway_match(this->opts.surf_matching_opts,
167 pfs_1.surf_descr.data()->begin(),
168 std::min(num_features, pfs_1.surf_descr.size()),
169 pfs_2.surf_descr.data()->begin(),
170 std::min(num_features, pfs_2.surf_descr.size()),
171 &surf_result);
172 return Matching::count_consistent_matches(surf_result);
173 }
174
175 return 0;
176}
177
179
util::AlignedMemory< math::Vec64s, 16 > SurfDescriptors
util::AlignedMemory< math::Vec128us, 16 > SiftDescriptors
The FeatureSet holds per-feature information for a single view, and allows to transparently compute a...
Definition feature_set.h:28
Surf::Descriptors surf_descriptors
The SURF descriptors.
Definition feature_set.h:72
Sift::Descriptors sift_descriptors
The SIFT descriptors.
Definition feature_set.h:70
std::vector< Descriptor > Descriptors
Definition sift.h:153
std::vector< Descriptor > Descriptors
Definition surf.h:99
T const & clamp(T const &v, T const &min=T(0), T const &max=T(1))
Returns value 'v' clamped to the interval specified by 'min' and 'max'.
Definition functions.h:204
T round(T const &x)
Removes the fractional part of the value to the closest integer.
Definition functions.h:70
std::vector< Viewport > ViewportList
The list of all viewports considered for bundling.
#define SFM_NAMESPACE_END
Definition defines.h:14
#define SFM_NAMESPACE_BEGIN
Definition defines.h:13
Feature matching result reported as two lists, each with indices in the other set.
Definition matching.h:57
Representation of the SIFT descriptor.
Definition sift.h:138
Representation of a SURF descriptor.
Definition surf.h:84