I'm currently developing an Android app using OCR and I've reached the point where I'm calling the BaseAPI.init() method. I keep getting errors stating that the directory must contain tessdata as a subfolder. I've checked that the file directory contains the folder with the trainingdata file inside, and made sure I'm pointing to the right directory. I would really like to fix this.
The directory i'm pointing to is /mnt/sdcard/Image2Text/ . I've made sure that tessdata is a subfolder with the necessary language file inside.
Here is the code:
public static final String DATA_PATH = Environment.getExternalStorageDirectory().toString() +
"/Image2Text/";
....
File dir = new File(DATA_PATH + "tessdata");
dir.mkdirs();
if (!(new File(DATA_PATH + "tessdata/" + lang + ".traineddata")).exists()) {
try {
AssetManager assetManager = getAssets();
InputStream in = assetManager.open("eng.traineddata");
OutputStream out = new FileOutputStream(DATA_PATH
+ "tessdata/eng.traineddata");
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {}
}
TessBaseAPI baseAPI = new TessBaseAPI();
baseAPI.init(DATA_PATH, lang);
baseAPI.setImage(new File(path));