-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr_main.cpp
More file actions
39 lines (28 loc) · 1.01 KB
/
Copy pathocr_main.cpp
File metadata and controls
39 lines (28 loc) · 1.01 KB
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
#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
string recognizedText;
string imagePath = argv[1];
// Define Initial Tesseract Object object
tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();
//Initialize OCR engine to use English (eng) and The LSTM OCR engine.
ocr->Init(NULL, "eng", tesseract::OEM_LSTM_ONLY);
// Set Page segmentation mode to PSM_AUTO (3)
ocr->SetPageSegMode(tesseract::PSM_AUTO);
// Open input image using OpenCV
Mat image = cv::imread(imagePath, IMREAD_COLOR);
// Set image data
ocr->SetImage(image.data, image.cols, image.rows, 3, image.step);
// Run Tesseract OCR on image
recognizedText = string(ocr->GetUTF8Text());
// Print recognized text in console
cout << recognizedText << endl;
// Kill used object and release memory
ocr->End();
return EXIT_SUCCESS;
}