-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
128 lines (99 loc) · 3.12 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <fstream>
#include <string>
#include <boost/filesystem.hpp>
#include "detector_harrisa.hpp"
using namespace std;
namespace fs = boost::filesystem;
int hamming_distance(const vector<bool>& vec1, const vector<bool>& vec2)
{
if( vec1.size() != vec2.size() )
return -1;
int distance = 0;
for(size_type i = 0; i < vec1.size(); ++i)
{
if( vec1[i] != vec2[i] )
++distance;
}
return distance;
}
double comparison_descriptor(const vector<descriptor_type>& img1, const vector<descriptor_type>& img2)
{
unsigned int number_similar = 0;
unsigned int number_varioous = 0;
unsigned int max_distance = 105;
for( auto dis1 = img1.begin(); dis1 != img1.end(); ++dis1 )
{
bool q = false;
for( auto dis2 = img2.begin(); dis2 != img2.end(); ++dis2 )
{
int k = hamming_distance(*dis1, *dis2);
if ( hamming_distance(*dis1, *dis2) <= max_distance)
{
++number_similar;
q = true;
break;
}
}
if (!q)
++number_varioous;
}
if ( number_varioous == 0 )
number_varioous = 1;
return double(number_similar)/number_varioous;
}
int main(int argc, char *argv[])
{
ifstream file(argv[1]);
//ifstream file("/home/alexander/study/Алгоритмы/Harris/input.txt");
if(!file.is_open())
{
return 0;
}
detector_harrisa detecter;
vector<string> result;
vector<string> command;
string tmp;
while ( getline(file, tmp) )
{
if ( tmp != "" )
command.push_back(tmp);
}
if ( command.size() != 3 )
return 0;
string pattern_path = command[0];
string images_path = command[1];
string result_path = command[2];
matrix_type pattern_img_pixel = imread( pattern_path, 0 );
Mat_<Vec3b> img = imread(pattern_path, 1);
vector<key_point> key_point1 = detecter.search_key_point(pattern_img_pixel);
vector<descriptor_type> pattern_descriptor = detecter.search_descriptor( pattern_img_pixel );
fs::directory_iterator end_itr;
for ( fs::directory_iterator it( images_path ); it != end_itr; ++it )
{
string img_path = it->path().string();
matrix_type img_pixel = imread(img_path, 0);
vector<descriptor_type> img_descriptor = detecter.search_descriptor( img_pixel );
double k = comparison_descriptor( pattern_descriptor, img_descriptor );
if ( k >= 1)
{
result.push_back( img_path );
//cout<<" (Уверенность - "<<k<<")"<<endl;
}
}
ofstream file_result( result_path );
if (!file_result.is_open())
return 0;
for (const auto & it : result)
{
file_result << it << endl;
}
file_result.close();
// for(auto current = key_point1.begin(); current != key_point1.end(); ++current)
// {
// Point a(current->coordinates.x, current->coordinates.y);
// circle(img, a, 3, Scalar(0, 0, 255), 1);
// }
//
// imwrite("/home/alexander/study/Алгоритмы/Harris/resultK11111.jpeg", img);
return 0;
}