0

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?

2 Answers2

0

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

rmtheis
  • 5,992
  • 12
  • 61
  • 78
-1

The path to your assets is

 Uri path = Uri.parse("file:///android_asset/")
 String dataPath = path.toString();
Niels Masdorp
  • 2,534
  • 2
  • 18
  • 31
  • Sorry for my late answer. I used this code but I got the same exception​. –  May 02 '17 at 17:50