Skip to content

Commit 85b10d4

Browse files
author
Damir Porobic
committed
Set where windows checks for trained data
1 parent 70d0aa9 commit 85b10d4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/OcrWrapper.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ OcrWrapper::~OcrWrapper()
3131

3232
QString OcrWrapper::recognize(const QPixmap &pixmap) const
3333
{
34-
if (mTessApi->Init(nullptr, "eng") == 0)
34+
if (mTessApi->Init(getDataPath(), "eng") == 0)
3535
{
3636
auto pix = makePixFromPixmap(pixmap);
3737
mTessApi->SetImage(pix);
3838

39-
auto recognizedText = mTessApi->GetUTF8Text();
39+
auto recognizedText = QSharedPointer<char>(mTessApi->GetUTF8Text());
4040

4141
pixDestroy(&pix);
4242

43-
return QString::fromLatin1(recognizedText);
43+
return QString::fromLatin1(recognizedText.data());
4444

4545
} else {
4646
qCritical("Failed to initialize Tesseract");
@@ -57,3 +57,16 @@ PIX* OcrWrapper::makePixFromPixmap(const QPixmap &pixmap)
5757

5858
return pixReadMemBmp((l_uint8 *)byteArray.constData(), byteArray.size());
5959
}
60+
61+
const char *OcrWrapper::getDataPath()
62+
{
63+
#if defined(_WIN32)
64+
// Under Windows we expect the trained data to be next to the plugin
65+
// in as directory called tessdata
66+
return ".\\tessdata\\";
67+
#else
68+
// Under Linux/Unix/MacOS we expect the TESSDATA_PREFIX to point to the
69+
// trained data.
70+
return nullptr;
71+
#endif
72+
}

src/OcrWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class OcrWrapper
4040
QSharedPointer<TessBaseAPI> mTessApi;
4141

4242
static PIX* makePixFromPixmap(const QPixmap &pixmap);
43+
static const char *getDataPath();
4344
};
4445

4546
#endif //PLUGIN_OCR_OCRWRAPPER_H

0 commit comments

Comments
 (0)