-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextify.cpp
More file actions
34 lines (27 loc) · 801 Bytes
/
textify.cpp
File metadata and controls
34 lines (27 loc) · 801 Bytes
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
//
// textify.cpp
// main
//
// Created by Ramin Siahcheshmi on 2/22/15.
// Copyright (c) 2015 Ramin. All rights reserved.
//
#include "textify.h"
const char *textify(const char *filepath) {
const char *outText;
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(filepath);
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
// Destroy used object and release memory
api->End();
delete [] outText;
pixDestroy(&image);
return outText;
}