MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
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
10#include <iostream>
11
12#include "math/algo.h"
14#include "sfm/matching.h"
15
17
18void
19Matching::remove_inconsistent_matches (Matching::Result* matches)
20{
21 for (std::size_t i = 0; i < matches->matches_1_2.size(); ++i)
22 {
23 if (matches->matches_1_2[i] < 0)
24 continue;
25 if (matches->matches_2_1[matches->matches_1_2[i]] != (int)i)
26 matches->matches_1_2[i] = -1;
27 }
28
29 for (std::size_t i = 0; i < matches->matches_2_1.size(); ++i)
30 {
31 if (matches->matches_2_1[i] < 0)
32 continue;
33 if (matches->matches_1_2[matches->matches_2_1[i]] != (int)i)
34 matches->matches_2_1[i] = -1;
35 }
36}
37
38int
39Matching::count_consistent_matches (Matching::Result const& matches)
40{
41 int counter = 0;
42 for (int i = 0; i < static_cast<int>(matches.matches_1_2.size()); ++i)
43 if (matches.matches_1_2[i] != -1
44 && matches.matches_2_1[matches.matches_1_2[i]] == i)
45 counter++;
46 return counter;
47}
48
49void
50Matching::combine_results(Matching::Result const& sift_result,
51 Matching::Result const& surf_result, Matching::Result* result)
52{
53 /* Determine size of combined matching result. */
54 std::size_t num_matches_1 = sift_result.matches_1_2.size()
55 + surf_result.matches_1_2.size();
56 std::size_t num_matches_2 = sift_result.matches_2_1.size()
57 + surf_result.matches_2_1.size();
58
59 /* Combine results. */
60 result->matches_1_2.clear();
61 result->matches_1_2.reserve(num_matches_1);
62 result->matches_1_2.insert(result->matches_1_2.end(),
63 sift_result.matches_1_2.begin(), sift_result.matches_1_2.end());
64 result->matches_1_2.insert(result->matches_1_2.end(),
65 surf_result.matches_1_2.begin(), surf_result.matches_1_2.end());
66
67 result->matches_2_1.clear();
68 result->matches_2_1.reserve(num_matches_2);
69 result->matches_2_1.insert(result->matches_2_1.end(),
70 sift_result.matches_2_1.begin(), sift_result.matches_2_1.end());
71 result->matches_2_1.insert(result->matches_2_1.end(),
72 surf_result.matches_2_1.begin(), surf_result.matches_2_1.end());
73
74 /* Fix offsets. */
75 std::size_t surf_offset_1 = sift_result.matches_1_2.size();
76 std::size_t surf_offset_2 = sift_result.matches_2_1.size();
77
78 if (surf_offset_2 > 0)
79 for (std::size_t i = surf_offset_1; i < result->matches_1_2.size(); ++i)
80 if (result->matches_1_2[i] >= 0)
81 result->matches_1_2[i] += surf_offset_2;
82
83 if (surf_offset_1 > 0)
84 for (std::size_t i = surf_offset_2; i < result->matches_2_1.size(); ++i)
85 if (result->matches_2_1[i] >= 0)
86 result->matches_2_1[i] += surf_offset_1;
87
88}
89
#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
std::vector< int > matches_1_2
Definition matching.h:59
std::vector< int > matches_2_1
Definition matching.h:61