I am currently developing an Android application using OCR, and I have reached the point where I call the BaseAPI.init () method. I keep getting errors stating that the directory should contain tessdata as a subfolder. I checked that the file directory contains the folder with the trainingdata file inside, and make sure that I point to the correct directory. I would really like to fix it.
The directory I'm pointing to is / mnt / sdcard / Image 2Text /. I 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));
source share