2024-08-31 22:18:54 +03:00
|
|
|
#include <string>
|
|
|
|
#include <tesseract/baseapi.h>
|
|
|
|
#include <leptonica/allheaders.h>
|
2024-11-22 23:19:04 +03:00
|
|
|
#include <opencv2/opencv.hpp>
|
2024-08-31 22:18:54 +03:00
|
|
|
#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;
|
|
|
|
}
|