【发布时间】:2018-02-16 23:44:44
【问题描述】:
您好,我正在尝试使用 tess-two API 来制作 OCR 应用程序
我需要使用两种语言的训练数据
我从资产加载我的数据,但我不知道如何从中加载多个数据
这是我的代码:
private void checkFile(File dir) {
if (!dir.exists()&& dir.mkdirs()){
copyFiles();
}
if(dir.exists()) {
String datafilepath = datapath+ "/tessdata/eng.traineddata";
File datafile = new File(datafilepath);
if (!datafile.exists()) {
copyFiles();
}
}
}
private void copyFiles() {
try {
String filepath = datapath + "/tessdata/eng.traineddata";
AssetManager assetManager = getAssets();
InputStream instream = assetManager.open("tessdata/eng.traineddata");
OutputStream outstream = new FileOutputStream(filepath);
byte[] buffer = new byte[1024];
int read;
while ((read = instream.read(buffer)) != -1) {
outstream.write(buffer, 0, read);
}
outstream.flush();
outstream.close();
instream.close();
File file = new File(filepath);
if (!file.exists()) {
throw new FileNotFoundException();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
如何更改它以复制多个数据?
【问题讨论】:
标签: java android ocr tesseract android-assets