-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpredict.cpp
More file actions
87 lines (76 loc) · 1.71 KB
/
predict.cpp
File metadata and controls
87 lines (76 loc) · 1.71 KB
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
#include"FeatureExtractor.h"
#include"LinearSVM.h"
#include"predict.h"
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
using namespace visint_ocr;
int predict(const char* resultpath, const std::vector<std::vector<cv::Mat>>& vvM)
{
//加载字典
map<int, string> mistr;
ifstream inputmap("./body.map");
if (inputmap.fail())
return -1;
while (!inputmap.eof())
{
int l;
string hanzi;
inputmap >> l >> hanzi;
mistr[l] = hanzi;
}
inputmap.close();//加载完毕
ofstream output(resultpath);
if (output.fail())
return -1;//创建文件失败
string chars;
FeatureExtractor fex(4, 3);
fex.setPyramidLevel(3);
LinearSVM svm;
svm.load_svm_model("./body.model");
for (size_t i = 0; i < vvM.size(); i++)
{
for (size_t j = 0; j < vvM[i].size(); j++)
{
vector<float> features;//特征向量
fex.Extract(vvM[i][j], features);
int label =svm.predict_s(features);
chars += mistr[label];
}
chars+=" ";
}
output << chars;
output.close();
return 0;
}
int predict(const std::vector<std::vector<cv::Mat>>& vvM, std::vector<std::vector<int>>& vvi)
{
FeatureExtractor fex(4, 3);
fex.setPyramidLevel(3);
LinearSVM svm;
svm.load_svm_model("./head.model");
for (size_t i = 0; i < vvM.size(); i++)
{
for (size_t j = 0; j < vvM[i].size(); j++)
{
vector<float> features;//特征向量
fex.Extract(vvM[i][j], features);
int label = svm.predict_s(features);
vvi[i].push_back(label);
}
}
return 0;
}
//备用接口
int predict(const cv::Mat& charMat)
{
FeatureExtractor fex(4, 3);
fex.setPyramidLevel(3);
LinearSVM svm;
svm.load_svm_model("./body.model");
vector<float> features;//特征向量
fex.Extract(charMat, features);
int label = svm.predict_s(features);
return label;
}