-
Notifications
You must be signed in to change notification settings - Fork 1
/
tess.cpp
45 lines (34 loc) · 1.05 KB
/
tess.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
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <string>
#include <iostream>
#include "tess.h"
#include "string.h"
std::string run_tess(char const* image_input)
{
char *outText;
std::string response ("");
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
// Open input image with leptonica library
Pix *image = pixRead(image_input);
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
// Destroy used object and release memory
api->End();
//delete [] outText;
// print result
response.append("OCR output: ");
response = response + outText;
printf("\n");
std::cout << response << std::endl;
// free mem
pixDestroy(&image);
return response;
}