【发布时间】: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