-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_feature.cpp
90 lines (84 loc) · 2.79 KB
/
get_feature.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
#include"get_feature.h"
#include"lbp.cpp"
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<fstream>
#include<sstream>
#include <iomanip>
string FixedString(string x){
stringstream strStream;
strStream<<setw(4)<<setfill('0')<<x;
return strStream.str() + ".jpg";
}
void FeatureProcessor::LoadPair(){
ifstream in(FFileName);
string line;
int i = 0;
while(getline(in, line)){
if(i >= 1 && i <= 1100){
istringstream inn(line);
string x, a, b;
inn >> x >> a >> b;
pair<string, string> tmp(x + "/" + x + "_" + FixedString(a), x + "/" + x + "_" + FixedString(b));
fpair.push_back(tmp);
}
else if(i > 1100){
istringstream inn(line);
string x, y, a, b;
inn >> x >> a >> y >> b;
pair<string, string> tmp(x + "/" + x + "_" + FixedString(a), y + "/" + y + "_" + FixedString(b));
fpair.push_back(tmp);
}
i++;
}
ifstream in1(TFileName);
string line1;
i = 0;
while(getline(in1, line1)){
if(i >= 1 && i <= 500){
istringstream inn(line1);
string x, a, b;
inn >> x >> a >> b;
pair<string, string> tmp(x + "/" + x + "_" + FixedString(a), x + "/" + x + "_" + FixedString(b));
tpair.push_back(tmp);
}
else if(i > 500){
istringstream inn(line1);
string x, y, a, b;
inn >> x >> a >> y >> b;
pair<string, string> tmp(x + "/" + x + "_" + FixedString(a), y + "/" + y + "_" + FixedString(b));
tpair.push_back(tmp);
}
i++;
}
}
vector<double> calculate(vector<double> &x, vector<double> y){
for(int i = 0; i < x.size(); i++)
x[i] = x[i] + y[i] == 0 ? 0 : pow(x[i] - y[i], 2) / (x[i] + y[i]);
return x;
}
void FeatureProcessor::GetFeature(){
string path = "/Users/zhangqi/STUDY/qq/data/pre_data/";
cout<<"Preparint train set..."<<endl;
for(int i = 0; i < fpair.size(); i++){
LBPextractor A(path + fpair[i].first);
LBPextractor B(path + fpair[i].second);
vector<double> x1 = A.getFeature();
vector<double> x2 = B.getFeature();
vector<double> f = calculate(x1, x2);
feature.push_back(f);
}
cout<<"Preparint test set..."<<endl;
for(int i = 0; i < tpair.size(); i++){
LBPextractor A(path + tpair[i].first);
LBPextractor B(path + tpair[i].second);
vector<double> x1 = A.getFeature();
vector<double> x2 = B.getFeature();
vector<double> f = calculate(x1, x2);
test_feature.push_back(f);
}
}
vector<vector<double> > FeatureProcessor::OutFeature() {return feature;}
vector<vector<double> > FeatureProcessor::OutTestFeature() {return test_feature;}