我正在尝试复制文件以供 Tesseract 使用,无论我如何尝试,它都会给我 filenot found 异常。我不明白为什么,因为我将它们放在资产文件夹中。我通过复制不起作用的特定 tessdata 文件夹尝试了一种方法,因此我尝试将它们全部放在通用资产文件夹下,并将其中的每个文件复制到我在卡上创建的名为 tessdata 的新目录中。
这是文件夹中文件的图像、复制方法和发布的日志错误:
这是代码:
private void copyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
android.util.Log.e(TAG, "Failed to get asset file list.", e);
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
out = new FileOutputStream(tesspath+ "/" + filename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(IOException e) {
android.util.Log.e("tag", "Failed to copy asset file: " + filename, e);
}
}
}
-我还尝试使用从资产中的 tessdata 文件夹复制它们的示例中的此方法-
if (!(new File(tesspath + File.separator + lang + ".traineddata")).exists()) {
copyAssets();
/* try {
AssetManager assetManager = getAssets();
//open the asset manager and open the traineddata path
InputStream in = assetManager.open("tessdata/eng.traineddata");
android.util.Log.e(TAG, "OPENED SUCCESSFULLY IF NO ERROR BEFORE THIS");
OutputStream out = new FileOutputStream(tesspath + "/eng.traineddata");
android.util.Log.e(TAG, "WRITING NOW TO" + tesspath);
byte[] buf = new byte[8024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {
android.util.Log.e(TAG, "Was unable to copy " + lang
+ " traineddata " + e.toString());
android.util.Log.e(TAG, "IM PRINTING THE STACK TRACEs");
e.printStackTrace();
}
*/
} else {
processImage(STORAGE_PATH + File.separator + "savedAndroid.jpg");
}