Tesseract4Android - Could not initialize Tesseract API with language=eng

Viewed 44

I'm working on an android app that uses Tesseract4Android and followed the steps yet this error keeps occurring

I've made a folder "tesseract" in "sdcard/" and it contains "tessdata" with the *.traineddata files. Added install-time permission in the android manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

together with runtime permission request yet it doesnt recognize the traineddata files

This is in my MainActivity:

    val tess = TessBaseAPI()
    val dataPath = File("sdcard/", "tesseract").absolutePath
    if (!tess.init(dataPath, "eng")) {
        // Error initializing Tesseract (wrong data path or language)
        tess.recycle();
        return;
    }

I also tried using all versions of the traineddata one by one and it still shows this error

1 Answers

I found a solution for the people in the future with the same problem, even though that particular path is "correct" (tested with file functions) its incorrect. My solution was making a tessdata folder in internal storage (filesDir) and coppying the eng.traineddata to that tessdata folder and then calling

if (!tess.init(filesDir.absolutePath, "eng")) {
    // Error initializing Tesseract (wrong data path or language)
    tess.recycle();
    return;
}
Related