Can't do OCR with tess-two on Android Studio

1.6k Views Asked by At

everyone. I'm trying to include tess-two OCR library to an Android project but some issues occurred.

[What I'm trying to do]

Do OCR with tess-two (tess-two github link) on Android Studio.
(I'd like to develop some OCR apps)

[Where I'm stuck]

The app is forced to be terminated when run from Android Studio

[What I did]

  1. Downloaded tess-two
  2. built it
ndk-build
android update project --path C:\...\tess-two  
ant release
  1. Made a new project "test" on Android Studio (API 16, Blank Activity)
  2. Put classes.jar to test\app\libs
  3. Added classes.jar as a library to app
  4. Put directories with .so files (armeabi-v7a, mips, x86) to test\app\src\main\jniLibs
  5. Put the following code in MainActivity.java
import com.googlecode.tesseract.android.TessBaseAPI;

public void testOCR(){
    String storagePath = Environment.getExternalStorageDirectory().getPath();
    Bitmap bitmap = null;
    ImageView img = (ImageView) findViewById(R.id.imageView);

    // Read an image
    File file = new File("storage/sdcard1/tess-two/ocr_sample.jpg");
    if (file.exists()) {
        bitmap = BitmapFactory.decodeFile(file.getPath());
        bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
        img.setImageBitmap(bitmap);
    }else{
        Log.d("tess-two","File not found.");
        return;
    }

    // Init modules
    TessBaseAPI tessOCRAPI = new TessBaseAPI();
    tessOCRAPI.init(storagePath+"/tess-two/", "eng");

    // Set Image
    tessOCRAPI.setImage(bitmap);
    String recognizedText = tessOCRAPI.getUTF8Text();
    Log.d("tess-two",recognizedText);

    // Close OCR API
    tessOCRAPI.end();

}
  1. Ran the app on a smartphone.

Then, the app halted. I debugged it and the program seemed to halt at TessBaseAPI tessOCRAPI = new TessBaseAPI();. While debugging, the sentence below appeared at the debug windows.

com.android.internal.os.ZygoteInit$MethodAndArgsCaller

Rebuilding and cleaning the project and searching on google didn't give any good results.

Could anyone suggest a way to solve this issue? Thank you in advance!

[My environment]

  • Windows 8.1 Pro 64 bit
  • Android studio 1.3
  • Xperia SO-04F

[Reference]

0

There are 0 best solutions below