4

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));
dr3wmurphy
  • 186
  • 1
  • 7

1 Answers1

6

Like you say, the DATA_PATH directory must contain tessdata as a subfolder. So, if your tessdata folder was /data/data/tessdata, DATA_PATH would be /data/data I hope that this helps!

EDIT: ak, I think I missunderstood!

Andy
  • 76
  • 1
  • Right, that part I knew from reading the BaseAPI.java file. I've gone into the file system to check and make sure the directory is there, and sure enough it is. The directory in this case is /mnt/sdcard/Image2Text/. That directory contains tessdata as a subfolder. Am I incorrectly specifying it in my code? Also, my code SHOULD create the folder if it isn't. It does in my case, as I DO have android.permission.WRITE_EXTERNAL_STORAGE in the AndroidManifest.xml – dr3wmurphy Nov 08 '12 at 17:40