找不到Tesseract OCR Android tessdata目录 [英] Tesseract OCR Android tessdata directory not found

查看:459
本文介绍了找不到Tesseract OCR Android tessdata目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用OCR开发一个Android应用,并且已经达到了调用BaseAPI.init()方法的地步.我不断收到错误消息,指出该目录必须包含tessdata作为子文件夹.我检查了文件目录是否包含其中包含trainingdata文件的文件夹,并确保我指向了正确的目录.我真的很想解决这个问题.

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.

我指向的目录是/mnt/sdcard/Image2Text/.我已确保tessdata是其中包含必需语言文件的子文件夹.

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.

这是代码:

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));

推荐答案

就像您说的那样,DATA_PATH目录必须包含tessdata作为子文件夹.因此,如果您的tessdata文件夹为/data/data/tessdata,则DATA_PATH将为/data/data 我希望这会有所帮助!

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!

ak,我想我误会了!

这篇关于找不到Tesseract OCR Android tessdata目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆