Google PlusFacebookTwitter

Making a Simple OCR Android App using Tesseract

By on Nov 9, 2011 in Open Source | 489 comments

Share On GoogleShare On FacebookShare On Twitter

This post tells you how you can easily make an Android application to extract the text from the image being captured by the camera of your Android phone! We’ll be using a fork of Tesseract Android Tools by Robert Theis called Tess Two. They are based on the Tesseract OCR Engine (mainly maintained by Google) and Leptonica image processing libraries.

Recognizing text using your Android phone. Not exactly the end result of this blog post, but what you could achieve.

Note: These instructions are for Android SDK r19 and Android NDK r7c, at least for the time being (written at this tree). On 64-bit Ubuntu, you may need to install the ia32-libs 32-bit compatibility library. You would also need proper PATH variables added (see Troubleshooting section below).

  1. Download the source or clone this git repository. This project contains tools for compiling the Tesseract, Leptonica, and JPEG libraries for use on Android. It contains an Eclipse Android library project that provides a Java API for accessing natively-compiled Tesseract and Leptonica APIs. You don’t need eyes-two code, you can do without it.
  2. Build this project using these commands (here, tess-two is the directory inside tess-two – the one at the same level as of tess-two-test):
    cd <project-directory>/tess-two
    android update project --path .
    ant release
  3. Now import the project as a library in Eclipse. File -> Import -> Existing Projects into workspace -> tess-two directory. Right click the project, Android Tools -> Fix Project Properties. Right click -> Properties -> Android -> Check Is Library.
  4. Configure your project to use the tess-two project as a library project: Right click your project name -> Properties -> Android -> Library -> Add, and choose tess-two. You’re now ready to OCR any image using the library.
  5. First, we need to get the picture itself. For that, I found a simple code to capture the image here. After we have the bitmap, we just need to perform the OCR which is relatively easy. Be sure to correct the rotation and image type by doing something like:
    // _path = path to the image to be OCRed
    ExifInterface exif = new ExifInterface(_path);
    int exifOrientation = exif.getAttributeInt(
    int rotate = 0;
    switch (exifOrientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotate = 90;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotate = 180;
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotate = 270;
    if (rotate != 0) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        // Setting pre rotate
        Matrix mtx = new Matrix();
        // Rotating Bitmap & convert to ARGB_8888, required by tess
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
    bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
  6. Now we have the image in the bitmap, and we can simply use the TessBaseAPI to run the OCR like:
    TessBaseAPI baseApi = new TessBaseAPI();
    // DATA_PATH = Path to the storage
    // lang = for which the language data exists, usually "eng"
    baseApi.init(DATA_PATH, lang);
    // Eg. baseApi.init("/mnt/sdcard/tesseract/tessdata/eng.traineddata", "eng");
    String recognizedText = baseApi.getUTF8Text();

    (You can download the language files from here and put them in a directory on your device – manually or by code)

  7. Now that you’ve got the OCRed text in the variable recognizedText, you can do pretty much anything with it – translate, search, anything! ps. You can add various language support by having a preference and then downloading the required language data file from here. You might even put them in the assets folder and copy them to the SD card on start.

To make things easy, and for you to have a better understanding, I have uploaded a simple application on OCR that makes use of Tess Two on Github called Simple Android OCR (for beginners). If you want a full-fledged application, that has a selectable region while capturing the image, translating the text, preferences etc., then you can checkout Robert Theis’ Android OCR application (for intermediate+)!

Updated: 7 October 2012


  1. Using Tesseract Tools for Android to Create a Basic OCR App by Robert Theis
  2. Simple Android Photo Capture by MakeMachine
  3. tess-two README



  1. Japanese by datsuns
  2. French by Mathieu

Projects Made By Users

People have made a lot of projects using this tutorial, some of them are:

  1. DatumDroid by Aviral, Devashish and me
  2. MachineRetina by Salman Gadit

If you have made one too, do tell us in the comments below!


  1. Manivel Nagarajan

    April 29, 2014

    Post a Reply

    Wow… Superb job Gautam.. I done importing libraries like test-two and also assigned path to ndk build successfully… I solved all the errors.. But a problem, When I am trying to run, it shows an error message after captured image i.e, “Unfortunately your application has been stopped” .. I can’t find whats the mistake. Help me to run this app without any problem..

    • Adil Sher

      May 16, 2014

      I have same problem , if you solve it help me please?

    • HDR

      July 3, 2014

      Same happens to me, after taking the picture the app is stopped and there is this error in the LogCat:
      07-03 00:38:56.281: E/AndroidRuntime(3108): FATAL EXCEPTION: main
      07-03 00:38:56.281: E/AndroidRuntime(3108): Process:, PID: 3108
      07-03 00:38:56.281: E/AndroidRuntime(3108): java.lang.UnsatisfiedLinkError: Couldn’t load lept from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/"],nativeLibraryDirectories=[/data/app-lib/, /vendor/lib, /system/lib]]]: findLibrary returned null

  2. -JD-

    May 8, 2014

    Post a Reply

    Hi there!

    Is anybody who had same problem as me with Leptonica library?
    When I call findSkew on my image, it returns 0.0..:-(

    Float s = Skew.findSkew(ReadFile.readBitmap(image));

    I tried both methods…

  3. Priyank

    May 9, 2014

    Post a Reply

    Hi Gautam,i really admired about your OCR Blog, such a really nice one.
    but i don’t know it does not work for me in eclipse exactly of your code.
    can you guide me if i am on wrong somewhere. and also actally i don’t want to store image in sd card just directly read from image without save to sd card and bind to the EdittextBox. please bro help me an out from this.

  4. Adil Sher

    May 16, 2014

    Post a Reply

    I solved all the errors.. But a problem, When I am trying to run, it shows an error message after captured image press ok (ok,retake,cancel) it crash application i.e, “Unfortunately your application has been stopped” .. I can’t find whats the mistake. Help me to run this app without any problem..

  5. JM

    June 17, 2014

    Post a Reply

    sir I just want to ask I encounter this while i’m updating the android update project –path it says ” it seems that there are sub-projects. if you want to update them please use the –subprojects parameter”. How would I use the subproject parameter.. please help me I am a newbie in android.. thank you

  6. oscar

    June 24, 2014

    Post a Reply

    Hello, at the beginning :
    cd /tess-two
    android update project –path .
    ant release

    what does the android update project –path mean?
    I’m using windows, and can’t use those commands on cmd.

  7. Dinesh

    July 31, 2014

    Post a Reply

    Hi Mr.Gautam!
    I have used this Tesseract OCR App. It works perfectly.
    Thanks for publishing this App. I need to implement this in my app. Where i need to read the characters in an already saved JPEG image by OCR. In your coding where exactly, you are passing the image to read by the OCR. Kindly suggest any idea to call OCR by giving URI of the image.

    Thanks in advance. Looking forward for your valuable reply.

  8. Demon

    August 4, 2014

    Post a Reply

    java.lang.UnsatisfiedLinkError: Couldn’t load lept from loader
    dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/"], nativeLibraryDirectories=[/data/app-lib/, /vendor/lib, /system/lib]]]: findLibrary returned null

    • Robert

      September 10, 2014

      @Sharafkar @Sha @Demon

      You have to follow the instructions to *build* tess-two as well.

  9. sharafkar

    August 19, 2014

    Post a Reply

    Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load lept from loader dalvik.system.PathClassLoader[dexPath=/data/app/,libraryPath=/data/app-lib/]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(
    at java.lang.System.loadLibrary(

  10. Sha

    August 26, 2014

    Post a Reply

    Hi Mr. Gautam,

    I followed your Instructions
    First I imported Tess-Two from github:
    And linked it to my project
    The app compiles and runs fine. But after clicking an image when I hit done it crashes.

    And I think the problem is in here:
    TessBaseAPI baseApi = new TessBaseAPI();
    baseApi.init(DATA_PATH, lang);

    String recognizedText = baseApi.getUTF8Text();


  11. Mohamed

    September 9, 2014

    Post a Reply

    Hi, Thanks for this tutorial.

    I have a problem when I get to the baseApi.init(….) line. it stops and the log shows ” UnsatisfiedLinkError : cannot load library : reloc library[1306] : 1683 cannot locate ‘rand’ … ”

    Does that mean the building of the tess two went wrong ? if so, I kept redoing it and still the same error. What should I do ?

    Thanks :)

    • Robert

      September 10, 2014


      There’s a comment from an NDK team member on a related bug tracker issue that says you need to “unzip ndk64* on top of ndk32* to get all API levels for 32-bit development” because they changed some things around in NDK r10.

      Please open an issue on the tess-two project if you continue to see the problem.


  1. Tesseract OCR on Android is easier if you Maven-ise it, works on Windows too… | James Elsey - [...] to the lack of general resources available on the subject, I was able to find some good material by …
  2. Using Tesseract Tools for Android to Create a Basic OCR App « Software Projects - [...] an up-to-date tutorial available here, and I’ve collected the code in an Android project that should be easier to …
  3. Tesseracting Android | Giving Eyes To A Machine - [...] was to reconstruct a very simple OCR app. With the help of Gautam’s article from ‘‘ I was able …
  4. › Starting out with Simple-Android-OCR on ubuntu - […] pretty boring post. basically followed this tutorial […]

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>