-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.cpp
64 lines (54 loc) · 1.84 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
/*************************************************************************
> File Name: main.cpp
> Author: Bruce Zhang
> Mail: zhangxb.sysu@gmail.com
> Created Time: 2015年10月08日 星期四 15时14分01秒
************************************************************************/
#include "preprocess.h"
#include "cut.h"
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
/*
* 读取图片简历,分析存储文本行(textLine),切分(cut),
* 重切分(recut),合并(merge)
*/
void preprocessImage(char *filename) {
cv::Mat img = cv::imread(filename);
cv::Mat gray;
cvtColor(img, gray, CV_BGR2GRAY);
PreImageProcessor *pip = new PreImageProcessor(img);
pip->init();
vector<cv::Mat> textLines = pip->getTextLines();
vector<cv::RotatedRect> rotatedRects = pip->getRotatedRects();
vector<pair<int, int> > tlIndex = pip->getTextLineIndex();
pip->drawRectangles(img, pip->getRotatedRects());
// 创建和清空文本
fstream out("region.txt", ios::out);
out.close();
int len = textLines.size();
char myfile[16];
//cout << "序号\t汉字数\t英文数\t高度\t类型" << endl;
for (int i = 0; i < len; ++ i) {
Region region = cut(textLines[i]);
drawCutLine(region, i, "./tempFiles/cut");
reCut(region);
drawCutLine(region, i, "./tempFiles/recut");
merge(region);
drawCutLine(region, i, "./tempFiles/merge");
//divideLangRegion(region, i);
findTextlineType(region, i);
findPatchType(region, i);
findEnglishText(region, i);
saveRegionToFile(region, i, "region.txt", tlIndex[i].first, tlIndex[i].second);
}
}
int main(int argc, char** argv) {
if (argc != 2) {
cout << "Please specify the input image!" << endl;
return -1;
}
preprocessImage(argv[1]);
return 0;
}