3

I am trying to built an OCR Application in android using Tesseract Library.

Here is the code attached:

public class TessOCR {
    private TessBaseAPI mTess;

public TessOCR() {
    // TODO Auto-generated constructor stub

    mTess = new TessBaseAPI();
    String datapath = Environment.getExternalStorageDirectory() + "/tesseract/";
    String language = "sseg";
    File dir = new File(datapath + "tessdata/");
    if (!dir.exists())
        dir.mkdirs();
    mTess.init(datapath, language);


}

public String getOCRResult(Bitmap bitmap) {

    mTess.setImage(bitmap);
    String result = mTess.getUTF8Text();

    return result;
}

public void onDestroy() {
    if (mTess != null)
        mTess.end();
}

When I am calling new TessOCR() in my MainAcitivity It gives me the error

09-02 16:10:56.677 14225-14225/com.example.pulkitmital.swipetabtoolbar E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.pulkitmital.swipetabtoolbar, PID: 14225 java.lang.IllegalArgumentException: Data path must contain subfolder tessdata! at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:344) at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:317) at com.example.pulkitmital.swipetabtoolbar.TessOCR.(TessOCR.java:22) at com.example.pulkitmital.swipetabtoolbar.Tab1.doOCR(Tab1.java:326) at com.example.pulkitmital.swipetabtoolbar.Tab1.access$000(Tab1.java:42) at com.example.pulkitmital.swipetabtoolbar.Tab1$3.onClick(Tab1.java:168) at android.view.View.performClick(View.java:4785) at android.view.View$PerformClick.run(View.java:19884) at android.os.Handler.handleCallback(Handler.java:746) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

But the folder is already there.

Please help me to get rid of this problem.

3
  • Did you train your own language file called sseg.traineddata? The traineddata file should go in a subfolder named tessdata, which should go in your tesseract folder. Commented Sep 3, 2015 at 1:56
  • @rmtheis Yeah I have done it. Main Issue is that I forgot to add permission in manifest file Commented Sep 3, 2015 at 4:23
  • Glad you got it working. To help others, you should add your solution as an answer here, and check the check mark next to it to choose your own answer as the working solution. Commented Sep 5, 2015 at 3:02

2 Answers 2

1

Replace this line :

mTess.init(datapath, language);

with :

mTess.init(datapath + "tessdata/", language);
Sign up to request clarification or add additional context in comments.

3 Comments

I have already do the change that you told but its giving me error " Data path doest not exist!"
You could try create this folder after request mTess.init. Can you try it?
Thanks for your help. Actually the problem is that i forgot to add permission for reading storage in manifest file.
0

Basically Error is due to I forget to add permission to read from external storage in manifest file.

<uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="18" />

Just Add this line to your AndroidManifest and it will get resolved.


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.