Rene Dohan Rene Dohan - 7 months ago 112
Android Question

Tesseract tessdata folder not found when put in assets folder

I read everywhere that tessdata should be on external storage and there should be

language. But how to package application to device so it will be there ? I don't know about this is possible so I copied
folder. I can access it by
but when I when I try !
new File("file:///android_asset/tessdata/").exists()
it is not found and I get exception from tesseract library when initialising , that it is not found. I am using Genymotion as emulator and somehow that direct path is not correct. So I don't know what to do.


OK I have seen another example on github an he is copying traineddata from assets to sdcard if data there do not exist. So this is the only way probably.

 private void initializeTessApi() {
    _tessApi = new TessBaseAPI();
    File data = new File(application().dataDir(), TESSDATA);
    File traineddataFile = new File(data, LANG + ".traineddata");
    if (!traineddataFile.exists()) {
        try {
            copyAndClose(context().getAssets().open(TESSDATA + "/" + LANG + ".traineddata"), new FileOutputStream(traineddataFile));
            info("Copied", LANG, "traineddata");
        } catch (IOException e) {
            error(e, "Was unable to copy", LANG, "traineddata ");
    _tessApi.init(application().dataDir().getAbsolutePath(), LANG);