Skip to content Skip to sidebar Skip to footer

Could Not Initialize Tesseract Api With Language=eng

I am working on an Android app that requires OCR. I have decided to use Tesseract as API but I keep on getting this error: E/Tesseract(native): Could not initialize Tesseract API

Solution 1:

Are you using tess-two?. In your code:

TessBaseAPI ReadIt = new TessBaseAPI();
ReadIt.init("/storage/emulated/0/","eng");

"/storage/emulated/0/" path should be pointing to your data files. You must have a subdirectory named "tessdata". See https://github.com/rmtheis/tess-two/blob/d7a45fd2e08b7ec315cd1e29d1a7e0c72fb24a66/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java#L176

Read more at: Could not initialize Tesseract API with language=eng!

Solution 2:

Release permissions of manifest in Activity:

In manifest:

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

In onCreate:

if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    1);
        }
    }

Solution 3:

Tesseract-two isn't using the newest version of the OCR engine, it uses 3.05, so we are forced to use data from here. It seems the new data uses a different model, neural networks. The previous models before 4.0 worked differently.

I have tried using the data from here and here. These data sets are only compatible with the newest version of tesseract, 4.0 (source), so it won't work if you are using an older version of tesseract.

Solution 4:

If you dont use Marshmallow and still have problem try clean and rebuild project.

Solution 5:

I had this same issue and the problem was that Marshmallow specifically requires a new way for your app to get read/write permission to storage. This blog post solved my problem.

In my Main Activity I have the following:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    ...
    ...
    getStorageAccessPermissions(); // Request storage read/write permissions from the user
}

@TargetApi(23)
privatevoidgetStorageAccessPermissions() {
    int hasWriteStoragePermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (hasWriteStoragePermission != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(newString[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_WRITE_EXTERNAL_PERMISSIONS);
    }
}

Where REQUEST_CODE_WRITE_EXTERNAL_PERMISSIONS is an integer constant declared globally.

In a class that I have extending TessBaseAPI I added the following just for logging purposes to make sure that I actually can access the storage.

/* Checks if external storage is available to at least write to and returns the path name */privatestaticStringisExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    String retval = "External storage is not writable";
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        retval = Environment.getExternalStorageDirectory().toString();
    }
    return retval;
}

/* Checks if external storage is available to at least read from and returns the path name */privatestaticStringisExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    String retval = "External storage is not readable";
    if (Environment.MEDIA_MOUNTED.equals(state) ||
            Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        retval = Environment.getExternalStorageDirectory().toString();
    }
    return retval;
}

Post a Comment for "Could Not Initialize Tesseract Api With Language=eng"