-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocr.cpp
38 lines (31 loc) · 970 Bytes
/
ocr.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
#include <iostream>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <leptonica/bmp.h>
#include <opencv2/opencv.hpp>
#include "ocr.h"
#include "util.h"
namespace ocr {
using namespace std;
using namespace cv;
void Recogniser::recognise(const Mat &image, const vector<vector<Rect> > &lines,
string &text, bool black_on_white)
{
#if 0
display_image("recognise_chars image", image);
#endif
for_each(lines.begin(), lines.end(),
[&image, &text, black_on_white, this](const vector<Rect> &line) {
for_each(line.begin(), line.end(), [&image, &text, black_on_white, this](const Rect &bbox) {
Mat character(image(bbox));
char s[2] = {0, 0};
s[0] = recognise(character, black_on_white);
text.append(s);
#if 0 || defined(DISPLAY_INTERMEDIATE_IMAGES)
cerr << "Recognised char: " << s[0] << endl;
display_image("Recognising", character);
#endif /* 0 || defined(DISPLAY_INTERMEDIATE_IMAGES) */
});
});
}
}