blob: e6a074dae7eef4d1cf8e33a9fef3ef26caeedfdd (
plain) (
blame)
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
|
#include <chrono>
#include <leptonica/allheaders.h>
#include <tesseract/baseapi.h>
#include <vector>
// NOTE: Remember to update size and alignment in ocr hs module on change
struct OCRMatch {
int startX, startY;
int endX, endY;
const char *text;
};
// OCR configuration
#define CONFIDENCE_THRESHOLD 25.
#define MIN_CHARACTER_COUNT 3
const tesseract::PageIteratorLevel RESULT_ITER_MODE = tesseract::RIL_WORD;
// Preprocessing configuration
const float contrast = 0.3;
const float sharpness = 0.7;
const float scaleFactor = 1;
const float grayscaleWeightRed = 0.114;
const float grayscaleWeightGreen = 0.587;
const float grayscaleWeightBlue = 0.299;
extern "C" {
OCRMatch *findWordCoordinates(const char *image_path, /* returns */ int *size);
}
tesseract::TessBaseAPI *initializeTesseract();
Pix *loadImage(const char *imagePath);
std::vector<OCRMatch> extractTextCoordinates(const char *imagePath);
void printMatch(const OCRMatch &match);
void preprocessImage(Pix **image);
#define INLINE_IMAGE_PROC(process) \
temp = process; \
pixDestroy(image); \
*image = temp;
#define MEASURE(label, stmts) \
auto start = std::chrono::high_resolution_clock::now(); \
stmts; \
auto end = std::chrono::high_resolution_clock::now(); \
auto duration = \
std::chrono::duration_cast<std::chrono::microseconds>(end - start); \
std::cout << label << ": " << duration.count() / 1000.0 << " ms" << std::endl;
|