user5553995
user5553995

Reputation:

Tesseract traineddata path

I am trying to use tesseract-ocr in my android app. When I am trying to init() I get IllegalArgumentException because in this folder there is no 'tessdata' dir! Here is my project structure. project structure

Here I used InputStream and cacheDir:

private String getDirPath() {
    File f = new File(getCacheDir()+"/tessdata/");
    if (!f.exists()) try {

        InputStream is = getAssets().open("tessdata/eng.traineddata");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();


        FileOutputStream fos = new FileOutputStream(f);
        fos.write(buffer);
        fos.close();
    } catch (Exception e) { Log.e("error", e.toString()); }
    Log.i("wtf", f.getPath());
    return getCacheDir();
}

To init the Tesseract I have to pass 2 arguments - path to dir which contains directory 'tessdata' and second one is traineddata. Any ideas?

Upvotes: 0

Views: 1241

Answers (2)

rmtheis
rmtheis

Reputation: 5806

You can't refer to your app's raw asset files that way. Try using AssetManager instead.

Upvotes: 0

Niels Masdorp
Niels Masdorp

Reputation: 2428

The path to your assets is

 Uri path = Uri.parse("file:///android_asset/")
 String dataPath = path.toString();

Upvotes: -1

Related Questions