checks-parser/image/checkimage.cpp

24 lines
621 B
C++

#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>
#include "checkimage.h"
CheckImage::CheckImage(std::string path) {
this->path = path;
}
std::string CheckImage::parse_text() {
std::string result;
tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();
ocr->Init(NULL, "rus", tesseract::OEM_LSTM_ONLY);
ocr->SetPageSegMode(tesseract::PSM_AUTO);
cv::Mat im = cv::imread(this->path, cv::IMREAD_COLOR);
ocr->SetImage(im.data, im.cols, im.rows, 3, im.step);
result = std::string(ocr->GetUTF8Text());
return result;
}