srinivasan
srinivasan

Reputation: 685

Error while using tesseract to extract the text in the image using android

I built the tesseract ocr for android using android tesseract tool and everything went fine. I also got the library files. When I tried to use the java wrappers to access the native methods, the device crashes. I'm using the tesseract directly in camera callback.

The code looks something like this:

public class AndroidCamera extends Activity implements SurfaceHolder.Callback {

    TessBaseAPI tba;

    PictureCallback myPictureCallback_JPG = new PictureCallback() {

        public void onPictureTaken(byte[] data, Camera arg1) {
            Bitmap bitmapPicture = BitmapFactory.decodeByteArray(data, 0, data.length);
            tba = new TessBaseAPI();
            tba.setImage(bitmapPicture);
            String result = tba.getUTF8Text();
            Log.i("text: "+result);

            Toast.makeText(AndroidCamera.this,result,Toast.LENGTH_LONG).show();
        }
        camera.startPreview();
    };
}

I checked in the log cat still setimage it's working fine, in the tba.getUTF8Text() the device crashes.

Upvotes: 2

Views: 3607

Answers (1)

Anirudh
Anirudh

Reputation: 2524

I don't see any engine initialization code with the desired language. This is done by calling the init method with the language/directory.

    // if trained data is /mnt/sdcard/tessdata/eng.traineddata then 
    // the tesseractDirectory should be /mnt/sdcard/
    String tesseractDirectory ="path to tessdata dir";
    TessBaseAPI api = new TessBaseAPI();

    // eng - english language
    api.init(tesseractDirectory, "eng");
    // you may want to provide a grayscale/high contrast image for better results

Trained data can be downloaded here: http://code.google.com/p/tesseract-ocr/downloads/list

Upvotes: 3

Related Questions