File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -31,16 +31,16 @@ OcrWrapper::~OcrWrapper()
3131
3232QString 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+ }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments