5#include <tesseract/baseapi.h>
6#include <leptonica/allheaders.h>
7#include "OCRLanguageModel.h"
8#if TESSERACT_MAJOR_VERSION < 5
9#include <tesseract/strngs.h>
10#include <tesseract/genericvector.h>
39 ,m_tesseract(new tesseract::TessBaseAPI())
40 ,m_languages(new OCRLanguageModel(this))
42 if (m_tesseract->Init(
nullptr,
"eng"))
44 qDebug()<<
"Failed tesseract OCR init";
47 m_tesseract->SetPageSegMode(tesseract::PSM_AUTO);
49 std::vector<std::string> availableLanguages;
50#
if TESSERACT_MAJOR_VERSION < 5
51 GenericVector<STRING> languageVector;
52 m_tesseract->GetAvailableLanguagesAsVector(&languageVector);
53 for (
int i = 0; i < languageVector.size(); i++) {
54 availableLanguages.push_back(languageVector[i].c_str());
57 m_tesseract->GetAvailableLanguagesAsVector(&availableLanguages);
60 m_languages->setLanguages(availableLanguages);
73QRect OCS::area()
const
81 if(!url.isLocalFile())
83 qDebug() <<
"URL is not local :: OCR";
87 if (m_tesseract->Init(
nullptr, m_languages->getLanguagesString().c_str()))
89 qDebug() <<
"Failed tesseract OCR init";
93 m_tesseract->SetPageSegMode(tesseract::PSM_AUTO);
101 QImage img(url.toLocalFile());
103 img = img.copy(m_area);
106 m_tesseract->SetImage(img.bits(), img.width(), img.height(), 4, img.bytesPerLine());
110 Pix* im = pixRead(url.toLocalFile().toStdString().c_str());
111 m_tesseract->SetImage(im);
120void OCS::setFilePath(
QString filePath)
122 if (m_filePath == filePath)
125 m_filePath = filePath;
126 Q_EMIT filePathChanged(m_filePath);
129void OCS::setArea(
QRect area)
135 Q_EMIT areaChanged(m_area);
bool isEmpty() const const
QString fromStdString(const std::string &str)