forked from snavely/bundler_sfm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyMatch.cpp
98 lines (77 loc) · 2.41 KB
/
KeyMatch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/* KeyMatch.cpp */
/* Read in keys, match, write results to a file */
#include <time.h>
#include "keys2.h"
int main(int argc, char **argv) {
char *keys1_in;
char *keys2_in;
char *file_out;
double ratio;
if (argc != 4) {
printf("Usage: %s <keys1.in> <keys2.in> <out.txt>\n", argv[0]);
return -1;
}
keys1_in = argv[1];
keys2_in = argv[2];
ratio = 0.6; // atof(argv[3]);
file_out = argv[3];
clock_t start = clock();
short int *keys1, *keys2;
int num1 = ReadKeyFile(keys1_in, &keys1);
int num2 = ReadKeyFile(keys2_in, &keys2);
clock_t end = clock();
printf("Reading keys took %0.3fs\n",
(end - start) / ((double) CLOCKS_PER_SEC));
/* Compute likely matches between two sets of keypoints */
std::vector<KeypointMatch> matches =
MatchKeys(num1, keys1, num2, keys2, ratio);
#if 0
std::vector<KeypointMatch> matches_sym =
MatchKeys(num2, keys2, num1, keys1);
#endif
int num_matches = (int) matches.size();
// int num_matches_sym = (int) matches_sym.size();
printf("num_matches = %d\n", num_matches);
// printf("num_matches_sym = %d\n", num_matches_sym);
#if 0
/* Prune asymmetric matches */
for (int i = 0; i < num_matches; i++) {
int idx1 = matches[i].m_idx1;
int idx2 = matches[i].m_idx2;
for (int j = 0; j < num_matches_sym; j++) {
if (matches_sym[j].m_idx1 == idx2) {
if (matches_sym[j].m_idx2 != idx1) {
matches.erase(matches.begin() + i);
i--;
num_matches--;
}
break;
}
}
}
#endif
if (num_matches >= 16) {
FILE *f = fopen(file_out, "w");
/* Write the number of matches */
fprintf(f, "%d\n", (int) matches.size());
for (int i = 0; i < num_matches; i++) {
fprintf(f, "%d %d\n", matches[i].m_idx1, matches[i].m_idx2);
}
fclose(f);
}
}