-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpencvApi.cpp
60 lines (48 loc) · 1.95 KB
/
OpencvApi.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
#include "Params.h"
int main() {
string pos_root_path = string(TRAINSET_PATH) + string("Pos/");
string neg_root_path = string(TRAINSET_PATH) + string("Neg/");
std::vector<std::string> pos_paths;
std::vector<std::string> neg_paths;
GetImgNames(pos_root_path, pos_paths);
GetImgNames(neg_root_path, neg_paths);
std::vector<cv::Mat> image;
std::vector<int> lable;
for (auto i = pos_paths.begin(); i != pos_paths.end(); i++) {
// cout<<pos_root_path+*i<<endl;
cv::Mat t_image = cv::imread(pos_root_path+*i);
t_image = GetUsedChannel(t_image, L);
image.push_back(t_image);
lable.push_back(POS_LABLE);
}
for (auto i = neg_paths.begin(); i != neg_paths.end(); i++) {
cv::Mat t_image = cv::imread(neg_root_path+*i);
t_image = GetUsedChannel(t_image, L);
image.push_back(t_image);
lable.push_back(NEG_LABLE);
}
Ptr<FaceRecognizer> model = createLBPHFaceRecognizer();
model->train(image, lable);
pos_paths.resize(0);
neg_paths.resize(0);
pos_root_path = string(TESTSET_PATH) + string("Pos/");
neg_root_path = string(TESTSET_PATH) + string("Neg/");
GetImgNames(pos_root_path, pos_paths);
GetImgNames(neg_root_path, neg_paths);
int correct_sum = 0;
for (auto i = pos_paths.begin(); i != pos_paths.end(); i++) {
// cout<<pos_root_path+*i<<endl;
cv::Mat t_image = cv::imread(pos_root_path+*i);
t_image = GetUsedChannel(t_image, L);
correct_sum += model->predict(t_image);
}
cout<<correct_sum*1.0/pos_paths.size()<<endl;
correct_sum = 0;
for (auto i = neg_paths.begin(); i != neg_paths.end(); i++) {
cv::Mat t_image = cv::imread(neg_root_path+*i);
t_image = GetUsedChannel(t_image, L);
correct_sum += model->predict(t_image);
}
cout<<1 - correct_sum*1.0/neg_paths.size()<<endl;
return 0;
}