Tesseract OCR Android tessdata directory not found

社会主义新天地 提交于 2019-12-10 15:52:11

问题


I'm currently developing an Android app using OCR and I've reached the point where I'm calling the BaseAPI.init() method. I keep getting errors stating that the directory must contain tessdata as a subfolder. I've checked that the file directory contains the folder with the trainingdata file inside, and made sure I'm pointing to the right directory. I would really like to fix this.

The directory i'm pointing to is /mnt/sdcard/Image2Text/ . I've made sure that tessdata is a subfolder with the necessary language file inside.

Here is the code:

public static final String DATA_PATH = Environment.getExternalStorageDirectory().toString() +
                                            "/Image2Text/";


....

File dir = new File(DATA_PATH + "tessdata");
    dir.mkdirs();

    if (!(new File(DATA_PATH + "tessdata/" + lang + ".traineddata")).exists()) {
        try {

            AssetManager assetManager = getAssets();
            InputStream in = assetManager.open("eng.traineddata");
            OutputStream out = new FileOutputStream(DATA_PATH
                    + "tessdata/eng.traineddata");

            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (IOException e) {}
    }

    TessBaseAPI baseAPI = new TessBaseAPI();
    baseAPI.init(DATA_PATH, lang);
    baseAPI.setImage(new File(path));

回答1:


Like you say, the DATA_PATH directory must contain tessdata as a subfolder. So, if your tessdata folder was /data/data/tessdata, DATA_PATH would be /data/data I hope that this helps!

EDIT: ak, I think I missunderstood!



来源:https://stackoverflow.com/questions/13282731/tesseract-ocr-android-tessdata-directory-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!