#include<string>#include<fstream>#include<tesseract/baseapi.h>#include<leptonica/allheaders.h>#include<opencv2/opencv.hpp>usingnamespace std;usingnamespace cv;intmain(int argc,char* argv[]){
string outText;string imPath ="./images/3.jpg";// Create Tesseract objecttesseract::TessBaseAPI *ocr =new tesseract::TessBaseAPI();/*Initialize OCR engine to use English (eng) and The LSTMOCR engine.There are four OCR Engine Mode (oem) availableOEM_TESSERACT_ONLY Legacy engine only.OEM_LSTM_ONLY Neural nets LSTM engine only.OEM_TESSERACT_LSTM_COMBINED Legacy + LSTM engines.OEM_DEFAULT Default, based on what is available.*///中英文识别ocr->Init("./tessdata","chi_sim", tesseract::OEM_LSTM_ONLY);//英文识别//ocr->Init("./tessdata", "eng", tesseract::OEM_LSTM_ONLY);// Set Page segmentation mode to PSM_AUTO (3)// Other important psm modes will be discussed in a future post.ocr->SetPageSegMode(tesseract::PSM_AUTO);// Open input image using OpenCVMat im = cv::imread(imPath, IMREAD_COLOR);// Set image dataocr->SetImage(im.data, im.cols, im.rows,3, im.step);// Run Tesseract OCR on imageoutText =string(ocr->GetUTF8Text());std::ofstream fout("1.txt", std::ios::out);fout << outText;fout.close();// Destroy used object and release memoryocr->End();return EXIT_SUCCESS;}