我正在尝试在我的android应用程序中使用tesseract-ocr。当我尝试初始化()时,我得到了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,我必须传递两个参数- path到dir,其中包含目录'tessdata‘,第二个参数是traineddata。有什么想法吗?
发布于 2017-05-13 05:44:24
您不能以这种方式引用应用程序的原始资产文件。请尝试使用AssetManager。
发布于 2017-05-01 23:15:04
通向资产的路径是
Uri path = Uri.parse("file:///android_asset/")
String dataPath = path.toString();https://stackoverflow.com/questions/43719458
复制相似问题