【问题标题】:Tesseract traineddata path正方体训练数据路径
【发布时间】:2017-05-01 12:57:44
【问题描述】:

我正在尝试在我的 android 应用程序中使用 tesseract-ocr。当我试图 init() 我得到 IllegalArgumentException 因为在这个文件夹中没有'tessdata'目录!这是我的项目结构。 project structure

这里我使用了 InputStream 和 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();
}

要初始化 Tesseract,我必须传递 2 个参数 - 包含目录 'tessdata' 的 dir 的路径,第二个是 traineddata。 有什么想法吗?

【问题讨论】:

  • 你添加读取文件权限了吗?
  • 是的,我在开头添加了它们。

标签: android tesseract tess-two


【解决方案1】:

您不能以这种方式引用应用的原始资产文件。尝试改用AssetManager。

【讨论】:

  • 这里!我用其他方式编辑了我的帖子以获取目录路径。
  • 您编辑了您的帖子,使其成为一个完全不同的问题。请不要那样做。
【解决方案2】:

资产的路径是

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

【讨论】:

  • 对不起,我的回答迟了。我使用了这段代码,但我得到了同样的例外。
猜你喜欢
  • 2016-02-12
  • 2012-08-05
  • 1970-01-01
  • 1970-01-01
  • 2020-06-21
  • 2020-01-27
  • 1970-01-01
  • 1970-01-01
  • 2014-07-22
相关资源
最近更新 更多