Making a Simple OCR Android App using Tesseract

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

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
    ndk-build
    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(
            ExifInterface.TAG_ORIENTATION,
            ExifInterface.ORIENTATION_NORMAL);
    
    int rotate = 0;
    
    switch (exifOrientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotate = 90;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotate = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotate = 270;
        break;
    }
    
    if (rotate != 0) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
    
        // Setting pre rotate
        Matrix mtx = new Matrix();
        mtx.preRotate(rotate);
    
        // 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");
    baseApi.setImage(bitmap);
    String recognizedText = baseApi.getUTF8Text();
    baseApi.end();

    (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

References

  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

Troubleshooting

  • If you are using Android Studio, check this comment.
  • About updating PATH – You need to update your PATH variable for the commands to function, otherwise you would see a command not found error. For Android SDK, add the location of the SDK’s tools and platform-tools directories to your PATH environment variable. For Android NDK, use the same process to add the android-ndk directory to the PATH variable.
  • Maven-ising – Check this post by James Elsey. He also mentions that he got it working on Windows without any problems.
  • On Windows: “xcopy is not recognized.” Solution: Move xcopy.exe file from Windows\System32 folder to android-sdk\tools folder (or add %SystemRoot%\system32 to the PATH variable).
  • On Windows: “The project either has no target set or the target is invalid. Please provide a –target to the ‘android.bat update’ command.” Solution: Run the command
    android update project --path D:\Softwares\Studies\Android\OCR\Code_Project\tess-two-master\tess-two --target android-19
  • You may also try Ctrl+F-ing your problem on this page, someone might have already encountered it and posted a solution in the comments.

Translations

  1. Japanese by datsuns

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
  3. OCR Quickly by UrySoft

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

691 comments

  1. Hi, I’m a student and I have a school project. I’m going to make android OCR for Korean Character Recognition. I would like to use tesseract android open source library. I have googled a lot how to build the libjpeg.so, liblept.so and libtess.so from the following Tesseract android readme file. I tried on cygwin and ubuntu, but both of them ended up with some errors. While using Cygwin it said that no rule to make target, while using Ubuntu I succeeded in building libjpeg.so but while building liblept.so errors occurred which said that android/bitmap.h does not exist. Then I check my leptonica-1.68 folder, true there is no such folder and file. I downloaded bitmap.h from internet and put it under android folder but still the same problem. Can u help me out of this ? The deadline will be 1 month and 30 days ahead for me to finish my project and the will be judgement day.

    Thank You for your attention

    Regards,

    Priska

    1. I received the same error and solved it by editing tess-two/jni/Android.mk (as highlighted in step 2) so that the beginning looks something like:


      # NOTE: You must set these variables to their respective source paths before
      # compiling. For example, set LEPTONICA_PATH to the directory containing
      # the Leptonica configure file and source folders. Directories must be
      # root-relative, e.g. TESSERACT_PATH := /home/username/tesseract-3.00
      #
      # To set the variables, you can run the following shell commands:
      # export TESSERACT_PATH=path-to-tesseract
      # export LEPTONICA_PATH=path-to-leptonica
      # export LIBJPEG_PATH=path-to-libjpeg
      #
      # Or you can fill out and uncomment the following definitions:
      # TESSERACT_PATH := path-to-tesseract
      # LEPTONICA_PATH := path-to-leptonica
      # LIBJPEG_PATH := path-to-libjpeg

      TESSERACT_PATH := $(call my-dir)/../external/tesseract-3.01
      LEPTONICA_PATH := $(call my-dir)/../external/leptonica-1.68
      LIBJPEG_PATH := $(call my-dir)/../external/libjpeg

      You can also try running these in the Terminal before ndk-build in step 3:

      export TESSERACT_PATH=${PWD}/external/tesseract-3.01
      export LEPTONICA_PATH=${PWD}/external/leptonica-1.68
      export LIBJPEG_PATH=${PWD}/external/libjpeg

      Hope that it helps. 🙂

    2. Where to put the google translate API key & bing translator Client ID and Client Secret for translation?

    3. Hi Gautam, Thanks alot for such a helpful post. I am also an indian and doing my masters in augmented reality in Malaysia. Really proud to see our young indian blood like you solving out the worlds problems 🙂 God Bless you….keep up the good work brother.
      Salam/Peace

  2. Hello, I made the whole process and the project gives me tess-two errors:

    Requires Android compiler compliance level 5.0 or 6.0. Found ‘1 .4 ‘instead.

    I compiled with JRE 1.5, this is okay?

    Thanks in advance, greetings.

    1. Thanks!! I tried it and it is working ..

      Where can I get a library where an image is filtered to only get the blacks?, Ie., Eliminate funding of an image and be alone with the text to parse the OCR system

    2. https://play.google.com/store/apps/details?id=com.davecote.seesaytranslate
      Travel with See Say! Image to Speech translator, take a picture and translate!
      An app for android that takes a picture, and speaks the text aloud, in any language:)
      I was inspired by a Ted Talk that mentioned that not too long ago, this technology was available for around $10,000.00, for the visually impaired. Technology has come so far that I am able to write this app and release it for $1.99 🙂
      Similar to See Say – Picture to Speech, but the image recognition will translate from other languages to English.
      Also, gives option of Speech or Text, in case you don’t want your phone to speak (ie: in a university lecture:)
      GREAT for traveling! Imagine you are in a country and don’t understand the language, you can take a picture of a menu at a restaurant, and the items are read back to you in English!
      Enjoy!

    3. Oops I forgot to mention, I’ve posted the code, open source, in the description on Google Play:)

  3. I need your help for the android ocr app I am making as my project. I did all the steps successfully. I then imported your project along with tess-two in eclipse. It shows no errors, but it fails at run time. I really made a lot of error to sort it out. It’ll be great if you can be of any help.Contact me on my email id. I’ll be obliged.

  4. Hey Gautam,

    I tried following the steps listed by you in windows environment (using cygwin). However, I face this error after I do ndk-build:
    make: *** No rule to make target `//cygdrive/f/work/ocr_cc/newf/rmtheis-tess-two-1edb5e2/rmtheis-tess-two-1edb5e2/tess-two/external/leptonica-1.68/src/adaptmap.c', needed by `/cygdrive/f/work/ocr_cc/newf/rmtheis-tess-two-1edb5e2/rmtheis-tess-two-1edb5e2/tess-two/obj/local/armeabi/objs/lept//cygdrive/f/work/ocr_cc/newf/rmtheis-tess-two-1edb5e2/rmtheis-tess-two-1edb5e2/tess-two/external/leptonica-1.68/src/adaptmap.o'. Stop.

    I tried solutions mentioned at http://code.google.com/p/tesseract-android-tools/issues/detail?id=4#c16 but with no luck.
    I strongly suspect that there is a path problem because if you look at the path in the error, it looks like it is a absolute path problem. Can you suggest any work around?

    Thanks,
    Vishwanath

    1. That’s the same problem that was being faced by one of my friends, I tried to fix it via Teamviewer but couldn’t. I’d prefer if you develop on non-win system or contact Robert Theis, author of tess-two for help. 🙂

  5. Hi,
    Get error during build :
    utilities.cpp:19:28: error: android/bitmap.h: No such file or directory

    any idea ?
    tx
    ps
    the tesseract-android-tools are working for me

    1. Yes,I did all steps again , clone ,uncoment lines (12-18)in Android.mk and build . Get same error :

      Compile++ thumb : lept <= utilities.cpp
      tess-two/tess-two/tess-two/jni/com_googlecode_leptonica_android/utilities.cpp:19:28: error: android/bitmap.h: No such file or directory
      make: *** [tess-two/tess-two/tess-two/obj/local/armeabi/objs/lept//tess-two/tess-two/tess-two/jni/com_googlecode_leptonica_android/utilities.o] Fehler 1

    2. hi andrzej,

      I had the same problem as yours.

      Did u extract the android-ndk from terminal?
      I also extracted the file from terminal, but some file was missing. So I downloaded and installed the new android-ndk and extracted it by clicking the right mouse instead of using terminal.

      I suggest you to reinstall your android-ndk to the latest version. android/bitmap.h is included in android-ndk.

    3. hi,
      @priska , thanx for suggestion ,but the problem was building with NDK r6 .
      Now NDK r6b is building without any error, so this problem is solved.

      The other problem was by android update :
      android update project --path .
      Error: The project either has no target set or the target is invalid.
      Please provide a --target to the 'android update' command.

      For any one having this error : update your Android SDK Tools to r14/r15

  6. make: *** No rule to make target `//home/park/android-ndk-r7/App/tess-two/external/leptonica-1.68/src/adaptmap.c', needed by `obj/local/armeabi/objs/lept//home/park/android-ndk-r7/App/tess-two/external/leptonica-1.68/src/adaptmap.o'. Stop.

    error… help me

    1. I think there should be path problems: “//home/park/android-ndk-r7/” and “/lept//home/park/” which are invalid paths.

  7. Please help i got this error.

    c:\rmtheis-tess-two-1edb5e2\tess-two>c:\MyWork\android-ndk\ndk-build
    Install : libjpeg.so => libs/armeabi/libjpeg.so
    "Compile thumb : lept <= open_memstream.c
    "Compile thumb : lept <= fopencookie.c
    "Compile thumb : lept <= fmemopen.c
    "Compile++ thumb : lept <= box.cpp
    In file included from jni/com_googlecode_leptonica_android/box.cpp:17:
    jni/com_googlecode_leptonica_android/common.h:22:24: error: allheaders.h: No suc
    h file or directory
    jni/com_googlecode_leptonica_android/box.cpp: In function 'jint Java_com_googlec
    ode_leptonica_android_Box_nativeCreate(JNIEnv*, _jclass*, jint, jint, jint, jint
    )':
    jni/com_googlecode_leptonica_android/box.cpp:27: error: 'BOX' was not declared i
    n this scope
    ...
    make: *** [obj/local/armeabi/objs/lept/box.o] Error 1

    The box.cpp it not correct? any build source work please send to my mail.

    1. hmmm i can build on windows it generate those .so file but when test on my phone got error 2 more:
      1. NativeReadBitMap(ReadFile.java:203)
      2. SetImage(TessBaseAPI.Java:311)

      How to solve it problem 😀

    2. Nope, the fact that the files were created doesn’t necessarily mean the build worked. Give it a try on Linux.

  8. I made it following this post!!! The Simple Android OCR is a really cool app! I am playing it on my Nexus One now. During the whole process, I did not encounter any problem. Built it under Ubuntu 10.04 64bit.

  9. Hi , any one has some good source/Dok/links how to work with implemented functions of tesseract?
    How to use :
    api.setPageSegMode(mode)
    api.setRectangle(rect)
    api.getTextlines()
    also
    Binarize.otsuAdaptiveThreshold(pix);

    Binarize is important by ocr ,but I am getting no result … or I don’t know how to use it…

    1. That method returns a Pix object, so you would need to do:

      Pix myThresholdedImage = Binarize.otsuAdaptiveThreshold(pix);

  10. i am getting error of TessbaseApi .and its giving me error that googlecode can not be resolved to a type?

  11. thanks for this superb tutorial Gautam. It worked for me after couple of messy configurations on my Fedora boot. Wish you all the best for your future endeavors.

  12. Is it just me or is the text recognition really poor using the tesseract API? I tried this and most of what I got was garbage (picture taken with 8MP HTC Evo camera, moderately good light conditions, printed text black on white). Even with rmtheiss’ Android OCR app, I got very poor results, plus its pretty slow. Uploading the same image to Google Docs and using its OCR had way better results. I’ve been thinking about trying to use the Google Docs API to do OCR for me but not sure that’s a good idea, considering it uploads the file as a new google doc and that’s not what I want, I just need to be able to OCR it and then parse the text for key info, not save it. I could set up my own server for cloud OCR-ing but I see no point in that unless I can get better OCR results. Any suggestions on how to make the recognition better?

    1. Did you try the intermediate+ project?

      That project gave much better results. Currently, I’m not exactly sure why though. Perhaps, it’s because it allows the user to define an area of interest.

  13. hi Gautam.
    Thank you for amazing post !!

    I had tried to build Tesseract-Android, and never succeeded until I found this site!

    and I translated this information into Japanese on my blog.
    http://d.hatena.ne.jp/datsuns/20120105
    (sorry Japanese only…)

    I’m sure this will be good information for other Japanese engineers!!

    so many Thanks !!

  14. Hii, i tried this sample and i am getting dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; i am using windows xp, and i complied to get lib file using cygwin. The application runs up to image capturing after that i am getting force close error. can you pls help me where i am getting struck off. i am new to ndk and ocr integration.

    1. Hii, no i only tried on Windows, whats the alternative solution for this.. is there any source file available for ready to use.??

  15. I’ve been looking into getting a live camera preview working in the Android emulator. Currently the Android emulator just gives a black and white chess board animation. ..plz help me ?

    1. That’s the intended behavior–the chess board animation simulates a camera view.

      There’s some code online that you can try searching for that connects the video feed from your webcam to the camera input of the Android emulator. It will probably be somewhat challenging to set up, but I’ve heard that it works.

  16. dear Gautam

    i have a problem at step number 3 and error message said “ndk-build:command not found”

    please help me fix this thing

    thank you

    1. how do i add NDK directory to my PATH variable? i didn’t find note ini the post

      sorry im really newbie with this thing

    2. hi Gautam

      i have succeessfully passed the “ndk-build” step and advanced to the “android update project –path .” step but it didn’t work and error message said “android: command not found”

      what should i do to solve this problem

      thank you

    3. me too.
      i passed the “ndk-build” step.
      but when i try “android update project –path .” step, it didn’t work and error message said “android: command not found”

  17. hi Gautam

    i have problem again. when i tried to add library as the instruction number 5, there is nothing tess-two library. i think i missed something.

    please help me fix this thing

    thank you Gautam

  18. I’m working on MAC and I have Android SDK latest installed and got the NDK r6 butwhen I use the
    ndk-build I get the follwoing error whe it is trying to build the lept lib:

    Invalid attribute name:
    package
    Install : libjpeg.so => libs/armeabi/libjpeg.so
    SharedLibrary : liblept.so
    /Users/viph4367/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -ljnigraphics
    collect2: ld returned 1 exit status
    make: *** [/Users/viph4367/Tesseract/obj/local/armeabi/liblept.so] Error 1

    Any idea, what I may be missing or doing wrong here?

    Vijay

    1. Update:

      – downloaded Robert Tess-two
      – and used NDK r7 as he mentioned in his README
      – I still get an error while running ndk-build, but a differnet on:

      make: *** No rule to make target …/rmtheis-tess-two-0cddf3a/tess-two/jni/../external/leptonica-1.68/src/adaptmap.c’

      Any ideas??

    2. Latest Update:

      Got it working. My build term had some issues. I got a new term which solved the issues I was running into.

      Vijay

  19. i tried building using ndk-build but it gives the follwing error.
    Install : libjpeg.so => libs/armeabi/libjpeg.so
    make: *** No rule to make target `/home/sumit/Downloads/rmtheis-tess-two-0cddf3a/tess-two/jni/com_googlecode_leptonica_android/../..//home/sumit/Downloads/rmtheis-tess-two-0cddf3a/tess-two/external/leptonica-1.68/src/adaptmap.c', needed by `/home/sumit/Downloads/rmtheis-tess-two-0cddf3a/tess-two/obj/local/armeabi/objs/lept//home/sumit/Downloads/rmtheis-tess-two-0cddf3a/tess-two/external/leptonica-1.68/src/adaptmap.o'. Stop.

    I working with Ubuntu

    Thanks in advance!!

    1. Thanks for your reply Vijay. I have been using SDK r16 and NDK r7. I also got a fresh copyof tess-two. Nothing seems to be working. I also tried with NDKr5. Still no luck!!!

    2. I have the same problem with you. I believe they changed the code since my last compiling in early Dec 2011. Because I can compile my old cold successfully again but fail in the code downloaded from the repository today. The path is broken.

      I think maybe tess-two changed some path variables in January 04, 2012 when they tried to integrated the eyes-two code into the project. “com_googlecode_leptonica_android/../..//home/sumit/” and “/lept//home/sumit/” in the error message really look like a path setting problem. (“//” before home)

    3. I not sure how many people encounter this problem as us. It seems many people work well with the new release.

    4. I can’t reproduce this problem–I just pulled from the repository and it built successfully on NDK r7 and Android SDK Tools 16 on Ubuntu 11.04 by following the instructions here.

      Please let us know if you find the source of the problem.

    5. OK it looks like this problem is related to Ubuntu 11.10. Until I get a chance to fix it, try building on 11.04.

  20. I’ve updated the post to reflect the changes that it now works with SDK r16 and NDK r7. Also, it doesn’t require all those TESSERACT_PATH, LEPTONICA_PATH and LIBJPEG_PATH. 🙂

  21. I get this problem:

    android update project –path .
    Error: The project either has no target set or the target is invalid.
    Please provide a –target to the ‘android update’ command.

    When using Android SDK Tools r15. I’m currently upgrading to r16 and will try again.

  22. Thanks for your great post, Guatam.
    It helped me a lot and the examples work great too.

    I have a question.
    Is it possible to make ‘Tesseract’ recognize more than two languages at the same time?
    It seems to be that ‘Tesseract api’ is only initialized with one language even if I copy more language data files to sdcard.

    Any advice will be really appreciated.
    Thanks and have a nice day!!

    1. I don’t think that is possible currently. You may want to run the OCR multiple times, using different languages each time and put the strings together. 🙂

  23. Thank u so much for ur kind answer Gautam!! At least I’m now aware of what I need to do! Best luck for you:D

  24. Hey gatuam,
    I am working on OCR project and I came across your blog.
    I have been finding some difficulty in building
    android-NDK in MAC OSX LION, I downloaded its latest version r7 as you have mentioned, but when I give the path for ndk-build, it gives error as
    “ERROR: Cannot find ‘make’ program. Please install Cygwin make package or define the GNUMAKE variable to point to it.”
    There are no spaces in my ndk path also, It would be great if you help us out.

    Thanks

  25. 1.I complie in cygwin follow the readm steps..
    2. and import in my project(myocr) as library project.
    3. now when i try to run the program my application myocr.apk goes in android emulator and install but when the tes-two project library turns come it display the error that

    “Could not find tess-two.apk!”

    🙁
    Please Help

    1. Asad, as mentioned earlier in the post and the comments, it does not work on Windows even with Cygwin. Please try using an Ubuntu VM. 🙂

  26. 1. Is (my android library project) tess-two.apk also install on my android emulator yes or not ?
    If Yes then first time when i set up and run my ocr project this tess-two.apk also install in android, but after 4 or 5 times i dont know what i did wrong in my project settings it is not installing give error Could not find tess-two.apk!”

    2. The Tess-two Project was build using API 3.2 i changed it to android API 2.2 is it ok to change the API level ?
    cuz m using emulator in android API Level 2.2.

      1. I once faced the “Could not find tess-two.apk” error, but do not remember how I resolved it. Probably try reimporting it into eclipse as a library and building/running it once (within eclipse). Also, the app would not show any results on an emulator since the camera shows no text, as noted by rmtheis in earlier comments.
      2. Yes, it is ok to do that.
  27. s@ubuntu:~/Desktop/android-ndk-r7$ ./ndk-build NDK-LOG=1
    Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: home/s/Desktop/tess-two/jni/Android.mk
    /home/s/Desktop/android-ndk-r7/build/core/add-application.mk:133: *** Android NDK: Aborting... . Stop.

    we are using ubuntu 11.04 on VMware.Android.mk file is present in the required folder.Also we have tried it on android-ndk-r6b but the same error persists.Awaiting a solution.plz.

    1. Does it also fail when you run ndk-build from the “tess/tess-two” project directory (as specified in the instructions)?

  28. Hi Gautam

    i have downloaded the application’s source code that you made. i created a new project then used the code and then run it. i have been successful deploying this project to the android device. i run the application on the device, using camera to complete the action. i captured the picture and then process stopped unexpectedly.

    i found a couple of error messages on eclipse that refer to some of code lines

    1. line 211 at SimpleAndroidOCRActivity.java refers to this line of code :
    TessBaseAPI baseApi = new TessBaseAPI();

    2. line 35 at SimpleAndroidOCRActivity.java refers to this line of code :
    onPhotoTaken();

    3. line 47 at TessBaseAPI.java refers to this line of code :
    System.loadLibrary(“lept”);

    1. yes i have…therefore error on TessBaseAPI.java at line 47 appeared

      i think the errors related to TessBaseAPI.java, especially at line 47, it couldn’t load “lept”

    2. “3. line 47 at TessBaseAPI.java refers to this line of code :
      System.loadLibrary(“lept”);”
      Did you solve the problem? I get the same error.

  29. i’ve an issue:
    the program failed at “Before baseApi” LOG.

    W/dalvikvm(11691): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI;

    this is the error.
    how can i solve it?

  30. when i type the command ndk-build it gives following error

    install : libjpeg.so => libs/armeabi/libjpeg.so
    make: *** No rule to make target `/home/kashif/tess/tess-two/jni/com_googlecode_leptonica_android/../..//home/kashif/tess/tess-two/jni/../external/leptonica-1.68/src/adaptmap.c’, needed by `/home/kashif/tess/tess-two/obj/local/armeabi/objs/lept//home/kashif/tess/tess-two/jni/../external/leptonica-1.68/src/adaptmap.o’. Stop.

    and after android update project --path
    and ant release

    its sucessfully build.xml file. and when compile project to add library with simple android ocr then display error in logcat as follow

    02-17 17:42:57.369: E/AndroidRuntime(330): FATAL EXCEPTION: main
    02-17 17:42:57.369: E/AndroidRuntime(330): java.lang.ExceptionInInitializerError
    02-17 17:42:57.369: E/AndroidRuntime(330): Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load lept: findLibrary returned null

    please help me what i do i am totally stuck from 2 and half week.

  31. Just to let everyone know – just built tess on Windows 7 today 😉 I didn’t do anything special, only steps described in this article – no errors so far. Tomorrow I will try to configure tess in eclipse.

    1. Hi, i’m see in your comment that you’l try to configure tess on eclipse. I am trying too, but with no sucess. You did it? How? Please, i’m trying to find tutorials about and nothing concret until today.

  32. @Gautam and @rmtheis, i have a suggestion to you. Why not you record video on how to compile those things. from scratch to the end. because this project are really2x important. many of newbies wanna try to their own projects. i need you help on this. could you please do that?

    really appreciate.

  33. Hey,
    I successfully compiled tess-two and completed the steps up until 3, however when I tried to set it as a library in eclipse it wouldn’t save the “is library” setting. Anyone have a similar problem or a possible solution?

    Thanks

  34. when I run ndk-build, it fails complaining from the following errors:

    $ ndk-build
    make: /.../android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found

    Compile arm : jpeg <= jcapimin.c
    make: /.../android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found

    make: *** [obj/local/armeabi/objs/jpeg/jcapimin.o] Error 127

    The problem is that although it says "command not found", "arm-linux-androideabi-gcc" exists in the above path. Even when I run "arm-linux-androideabi-gcc" directly from /…/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ it gives the same error of "command not found"

    I also added ./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin to my PATH but still getting the same error. Even I tried different versions of ndk (7, 7b, 6b) still same error! seems to me the above gcc is meant for 32bit machines whereas my machine is "Linux 2.6.32-37-server x86_64". but I guess the ndk package should work for both 32 and 64bit. am I right? do I need to compile or build ndk before using it? I assume downloading and unpacking is all I have to do. right? how about sdk? I just downloaded and unpacked it at the same folder that I have my ndk. do I need to configure them to work with each other?

    1. It was the problem of machine. I tried it on Ubuntu 11.10 and everything worked perfectly!

  35. Hey Gautam,

    Currently I am trying to get tesseract android tools

    http://code.google.com/p/tesseract-android-tools/

    to work for me on Android. I have been going at this for about a week to no avail.

    I am running Win 7 64 bit with cygwin.

    I followed the instructions in the readme file and made many changes to the Android.mk files. Basically it was appending a slash to the path, so I had to manually hard code the paths of the individual files, or move to location of the files within the 3 packages to get it to build. However at the end of the build, I did not recieve a “Build Sucessful” notice, but the .so files were generated.

    I ported it to eclipse as is and used your code to get the extracted text.

    private static final String TESSBASE_PATH = "/mnt/sdcard/";

    Bitmap imageFile = BitmapFactory.decodeFile(image.getAbsolutePath());

    TessBaseAPI baseApi = new TessBaseAPI();

    if(baseApi.init(TESSBASE_PATH, "eng")){
    System.out.println("Tessbase initialized");
    baseApi.setDebug(true);
    baseApi.setImage(bmp);
    String recognizedText = baseApi.getUTF8Text();
    System.out.println("---------------------output-------------------");
    System.out.println("recognizedText");
    }
    else{
    System.out.println("Tessbase initialization failure.");
    }

    At first I was getting an error saying

    “Bitmap functions not available; library must be compiled under android-8 NDK”

    After taking a look at the tessbaseapi.cpp file I realized that it needed a specific compiler flag to compile the correct function. This flag was -DHAS_JNIGRAPHICS. What I think this means is that the JNI Graphics library must be present.

    Yet the program still wouldn’t compile because the memcpy() function in the newly compiled method could not be found. I fixed this by changing the actual C++ code to include

    Finally the program compiled fully (still wasn’t getting a BUILD SUCCESSFUL notice though) and when I ran it, I did not get any output at all. This could be a problem with the eng.traineddata file, or could be a problem in the actual code.

    Is there anything I have done wrong? Can someone link me to and eng.traineddata file that they know works and image that works with it?

    Thanks in advance!

  36. Gautam accoring to this page
    http://developer.android.com/guide/developing/projects/index.html#LibraryProjects
    , the android library project does not contain .apk extension file and it does not install on your device. ok
    that was a confusion for me now i fix it, so now i m stuck in this instruction :
    baseApi.init(myDir.toString(), “eng”);
    my android application install work fine every thing when it comes to this instruction my application crash.
    also i tried manually specifying the directory
    api.init(“/mnt/sdcard/tesseract/tessdata/”, “eng”);
    still error application crash.
    and also check in my emulator SD-card no directory are their of tesseract in sdcard.
    please tell me what i m doing wrong.

    1. You need to make the application copy the english trained data from its resources folder (you’d have to manually place that in that) to the sdcard on installation/run. You can have a look at that code in the Simple Android OCR application here.

  37. There is a lot of discussion around this only working on Ubuntu.

    I’m thinking, once you’ve built it for the first time, could you not just copy it over to windows and never be bothered about Ubuntu again?

    Also, can’t the android library project be bundled up so you build it once and just import anywhere else for general usage? Maven might be an option for this.

    1. It may be possible to just distribute the library as a JAR file with the object files added to it.

      Releasing the pre-compiled library project on Maven or elsewhere, or tweaking the makefiles so it actually builds on Windows are also workable I think.

  38. Hey gautam i am planning to incorporate OCR in my app for reading pattern from using camera without taking a picture (just like we see in QR reader).i read your article but i couldn’t find anything for windows.i am using windows 7 windows OS and eclipse for developing this app.can u tell me what are the steps for using tesseract ?

  39. getting force close after taking photo.error is at TessBaseAPI.please help me.will this project work on ecilpse in windows??

  40. It worked in my application good. But when I changed my application version to 2.3.3 (from 4.0) it gives me error
    Android Launch!
    [2012-03-05 13:33:36 - fyp2] adb is running normally.
    [2012-03-05 13:33:36 - fyp2] Performing nicatoid.fyp2.Fyp2Activity activity launch
    [2012-03-05 13:33:36 - fyp2] Automatic Target Mode: Preferred AVD 'my_adv_google' is available on emulator 'emulator-5554'
    [2012-03-05 13:33:36 - fyp2] Uploading fyp2.apk onto device 'emulator-5554'
    [2012-03-05 13:33:38 - fyp2] Installing fyp2.apk...
    [2012-03-05 13:33:43 - fyp2] Success!
    [2012-03-05 13:33:43 - fyp2] Project dependency found, installing: tess-two
    [2012-03-05 13:33:43 - tess-two] Uploading tess-two.apk onto device 'emulator-5554'
    [2012-03-05 13:33:45 - tess-two] Installing tess-two.apk...
    [2012-03-05 13:33:46 - tess-two] Installation error: INSTALL_FAILED_OLDER_SDK
    [2012-03-05 13:33:46 - tess-two] Please check logcat output for more details.
    [2012-03-05 13:33:46 - fyp2] Launch canceled!

    How can I fix it? // I changed target sdk to 10 minimumsdk version to 10 but still error occurs.

    Thanks.

  41. Can you guide step-by-step how to install NDK? i have refer severals website, still don’t understand.

    1. if you follow step by step instructions from this site actually you don’t need any other NDK setting up process….just extract it

      i think step by step instructions from this site are obvious

      maybe you shouldn’t combine instructions from few source if you really don’t understand the problem

      i suggest you follow the instructions from beginning in this site…i have followed step by step instructions from this site and i have succesfully made OCR application using Tesseract engine

      CMIIW

  42. When i install http://subclipse.tigris.org/update_1.6.x , these error occurs. Subversion Native Library not available.

    Failed to load JavaHL Library.
    These are the errors that were encountered:
    no libsvnjavahl-1 in java.library.path
    no svnjavahl-1 in java.library.path
    no svnjavahl in java.library.path
    java.library.path = /usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386::/usr/java/packages/lib/i386:/usr/lib/jni:/lib:/usr/lib

    what actually i am lacking yah?

  43. i got a problem. when the time i gonna pui-in this command into the terminal, the termina said “couldn’t find package ia32-libs”. i tried googling but still, no luck.

    sudo apt-get install vim chromium-browser eclipse-platform libarchive-zip-perl libtext-csv-xs-perl libxml-simple-perl git-core gitosis subversion mercurial ia32-libs conky-all proguard gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev x11proto-core-dev libx11-dev lib32readline5-dev lib32z1-dev libgl1-mesa-dev libarchive-zip-perl libfile-find-rule-perl subversion build-essential g++ pkg-config gawk libxml2 libxml2-dev libxml2-utils xsltproc flex automake autoconf libtool libpcre3-dev

  44. Really useful, it works at first attempt.
    But it can’t configure it to read only digits. i’ve to OCR .gif images like this one http://goo.gl/9NXrQ and it recognize it as “os/5614360…” i tried with
    baseApi.setVariable(“tessedit_char_whitelist”, “0123456789”);
    but seems not work, it always recognize starting numbers as “os”/56…
    Can you solve me this problem? Many thanks!!!

  45. I’m getting this error…..
    The project cannot be built until build path errors are resolved …
    what do i do ? let me know the solution

  46. Hello Gautam,

    I have two doubts:
    1) Can i use Cygwin Terminal in windows for running both leptonica and tesseract? I have read somewhere it do the same.
    2)Why i cnt run it in only device containing android 4 os?

    Please help me. I am stuck on it.

    Thax,
    Dhrupal

  47. Hi Gautam ndk-build command was sucessful,but I am facing some problem at android update project –path,I am giving tess-two path but is is sating invalid directory

  48. Sometimes, Cygwin requires full rights to compile…
    chmod -R a+rwx tess-two
    Would save the day 😀

  49. getting ERROR:

    make: *** No rule to make target `/cygdrive/c/Users/JENIL/Downloads/rmtheis-tess-two-071820a/rmtheis-tess-two-071820a/tess-two/jni/com_googlecode_leptonica_android/../..//cygdrive/c/Users/JENIL/Downloads/rmtheis-tess-two-071820a/rmtheis-tess-two-071820a/tess-two/jni/../external/leptonica-1.68/src/gifio.c', needed by `/cygdrive/c/Users/JENIL/Downloads/rmtheis-tess-two-071820a/rmtheis-tess-two-071820a/tess-two/obj/local/armeabi/objs/lept//cygdrive/c/Users/JENIL/Downloads/rmtheis-tess-two-071820a/rmtheis-tess-two-071820a/tess-two/jni/__/external/leptonica-1.68/src/gifio.o'. Stop.

    plz suggest me solution…

  50. Hey I am Sayali a final year student of Computer Engineering and as our BE project we are making an OCR android app like yours.We have followed your steps and are working on ubuntu 10.10 but after the ndkbuild step we are getting some random error about adaptmap which we cant sort out. Can you please help us??

    1. Hey Sayali,
      I have got the same error. How did you solve the issue? Please help.

  51. Awesome stuff. Helped me a lot in my android project. Thanx Gautam! Keep up the good work! =)

  52. I was able to do this all on windows without any hassle, just followed tutorial and compiled from the command line, so it’s not linux only :S

    Results were rather poor, I gave it an image of a car, and instead of spotting the numberplate, it basically tried to create a textual representation of the car itself, like ASCII art..

  53. Gautam,

    I have problem android update project –path. I try to click the “About updating PATH” under troubleshooting, but the link not work/come out.

    Where to refer? Can you give me step-by-step on this?

  54. Hey JAMES…could you please tell me how to use ndk-build … where to use this command..pls pls pls .. i’m newbie to android platform..

  55. @rmtheis, after i edit the android.library=true to the project.properties file, i successfully cheik Is library box.But, when i want to add tess-two in project selection, there were nothing come out. just a blank. where’s my mistake?

    project selection are empty.
    ERROR: resource directory '/home/aminalzanki/workspace/tess-two/res' does not exist

    1. Same problem here. The “Is Library” is already checked but when I clicked Add button, the window displays no selection for tess-two library

      Thank you for your reply.

  56. HI,

    I have downloaded ur sample project and built the ndk also. I cant understand where we are actually implementing the eng.trainnedata from the assets folder. because i dont see any comparison of the image with the buffered trainned-data file.

  57. hey moreover it will be very much helpful if any of u can provide me a method to ocr an image by uploading via sd-card (not via camera)

  58. If you want to compile your code without Linux, you can use [Cygwin] (here) which emulates a BASH (= more or less a Linux Terminal).

  59. Hi Gautam, i’m going to develop an android app that compares two images and displays the name of the picture if the two images are similar. I should compare only the contents of the image, not the pixels. I mean the two images may be in different sizes but they should be same when we compare. How can i achieve this image recognition in android? Can you recommend any open source library which can achieve this in android?
    Thanks!

    1. This is not something that Tesseract is meant for, but such technologies do exist. Such content recognition is done by Google Goggles and something similar was accomplished by a friend I met in an event, whom I am no more in touch with. You might find something by Googling more.

  60. @gautam, @emtheis..After i check the Is Library, and want to choose tess-two, the tess-two wont come out. There are just empty. So, i dont know how adding a reference to a library project in the properties of an application project in my case.

    many thanks.

    1. Amin.

      I am facing the same problem as you. And i am still unable to resolve it. When i click the add button (in the ‘is library’ frame, the entire window is greyed out with only Cancel being active. So i am also stumped there.

      AJ

  61. I would like to develop an android app that can recognize handwriting words written on the touch screen of the android phone in real-time(on-line).
    How can I do this with tesseract?

    1. This is not something that Tesseract is meant for, but such technologies do exist. You might find them by Googling more. 🙂

  62. Hi Gautam, isn’t binarization of the image required before we make a call to getUTF8Text() ?

    Thanks,
    Shamy

    1. One more doubt… I have followed the steps you described and I got my app working. But I want to know whether I will able to debug through the Tesseract C++ code and if yes how?

      Thanks,
      Shamy

  63. I will hope to develop application as your one for my BSC degree. As I read your comments, you have mentioned this is not working in windows. Please can u tell what the changes to run this application on windows.

    1. It may build on Windows (not Cygwin–just Windows) by itself.

      If not, you can build tess-two on Linux, transfer the library folder to Windows, and add that folder as a library project in your OCR app.

  64. Is it possible to build the tess-two library in Ubuntu 11.04 (VirtualBox), then transfer the built library into windows and develop an app around it there, or will that not work? I seem to have successfully built tess-two, but when trying to build your Simple Android OCR project or rmtheis’s OCR Test, I haven’t been successful.

    Thanks!

    1. Yes–that should work. I build the library that way and share the tess-two folder in Shared Folders.

      One thing to check would be to just try instantiating a TessBaseAPI object in onCreate() in a small test app to see if that works by itself first:

      TessBaseAPI baseApi = new TessBaseAPI();
      // then try baseApi.init() and check for messages in LogCat
      baseApi.init("/mnt/sdcard", "eng", TessBaseAPI.OEM_TESSERACT_ONLY);

    2. Thanks for your reply. I’ve tried your suggestion, but keep getting the native error, “Could not initialize Tesseract API with language=eng!” on init() when I try to build.

      The error seems sort of vague and so far haven’t found any solutions online. Any ideas?

    3. I think the problem was that I didn’t have the English language files in my tessdata folder.

  65. ant release then following error:
    /root/tess/tess-two/src/com/googlecode/leptonica/android/Jpeg10.IO:68 error: can not find symbol
    symbol: variable FROYO
    BUILD FAILED
    /root/android-sdk-linux/tools/ant/build.xml:651 The following error occured while executing this line:
    /root/android-sdk-linux/tools/ant/build.xml:672 Compiled failed; see the compiler error output for details

    I am using android sdkr16, android ndk7 and ubuntu 11.04
    Please help me …

  66. Okey, I just successful build in jdk1.6. But Froyo can not resolved or is not field JpegIO.java, ReadFile.java, WriteFile.java.

  67. I’m almost done configuring it on windows 7 with cygwin, however I encountered following error :

    C:\Software\tess\android-ndk-r7c\tess\tess-two>android update project --path .
    Error: The project either has no target set or the target is invalid.
    Please provide a --target to the 'android.bat update' command.

    How can I solve this? Here I am not sure what “project” refers to.

  68. hi,
    keep up the awesome work.I’ve developed an ocr system using opencv and tesseract. But i need to run it on atom kit which is loaded with windows 7(customized). Can you please give me your suggestions on this. I’m calling the tesseract from the command prompt. do i need to run tesseract on the atom kit as well? the kit has the vc++2010 redistributable.(app built in vc++ 2010).
    Thanks

  69. Hi, I followed your guide to run tess-two on Ubuntu 11.10. Everything went good until I had to update project with command :
    android update project --path .
    A following error occured :
    Project either has no target set or the target is invalid. Provide option -t with update command.
    So I provided the target with ID “1”, which has following description :
    Android 4.0.3 , API level : 15, Revision : 3, ABIs : armeabi-v7a
    and it updated correctly.
    Then there was some error while importing the project in eclipse stating that something was wrong with “res” directory, but I did Fix Project Properties and it seems ok now. And now I am stuck at step when I should add libarary.. but I can’t. When I try to :
    Right click your project name -> Properties -> Android -> Library -> Add, and choose tess-two, I can’t choose anything ( and there is nothing on the list, especially not “tess-two” ), OK button is disabled, and box named “Please select a library project” is also disabled.
    Any ideas what to do know?

    Thanks

  70. Hi, I’m new to this so can you please tell me how to use ant release command. Im working on windows 7 PC. when I run it on command prompt it returns
    C:\Users\raveen>ant release
    'ant' is not recognized as an internal or external command, operable program or batch file."

    1. solved it, my bad I forgot to set environment variable, any way great article this is. 🙂

  71. What is and how to set DATA_PATH, lang in below line?

    baseApi.init(DATA_PATH, lang); baseApi.setImage(bitmap);

  72. Same problem as koleS’. I am stuck at step when I should add libarary, but I can’t. When I try to:
    Right click your project name -> Properties -> Android -> Library -> Add, and choose tess-two, I can’t choose anything (and there is nothing on the list, especially not “tess-two” ), OK button is disabled, and box named “Please select a library project” is also disabled.
    Any ideas what to do know?

    1. Actually I did a silly thing, because I wanted to add the library to… itself!
      When you set your library properly you then have to add it in another project, in which you want to use the library. Then options to add it will be enabled.

  73. Thanks for this great tutorial it helped me greatly but can you be more specific about how to change the language of data using the training data in tesseract site.
    By the way I did the steps in the tutorials and it works.

    1. 1. Download a new language data file and extract it to your data directory
      2. Change the string parameter to baseApi.init to match the new language’s three-letter code

  74. Do you need to do any “training” of the OCR engine? I’m trying to use this to read car registration plates, road signs etc, however rather than performing OCR on the given image, it attempts to “draw” it using characters, giving something that resembles ASCII art..

    Any suggestions? Thanks

    1. Try the HydrogenTextDetector class in the eyes-two project.

      Training will help detect a particular font consistently, so I expect it would help for registration plates and road signs since they should always use the same fonts. But I don’t expect training to help find the text areas within a large image.

      If you know you can expect your text and background colors to be consistent every time, you could try running custom thresholding based on that to pass a high-contrast image to the OCR engine.

    2. I’m getting incredibly varied results, if I try the following image :
      http://carandvannews.co.uk/wp-content/uploads/2012/04/12Plate.jpg

      Then I get “YTI2 ULR” which is close enough.

      However, if I try :
      http://www.v1seo.co.uk/v1seo-polo.jpg

      Then I get about 5 lines of nonsense, just special characters or random gibberish.

      I’ve followed all the resources I can find, and have looked at your Github project, but I’m still not able to get any reliable recognition working across various images.

      Is there some way of setting regions, so when trying to OCR a number plate it would look for a yellow/white rectangle and only OCR on that particular area? That would help improve results, but I can’t find any good examples.

      Thanks

  75. Hi rmtheis and gautam,
    I think i have compiled the entire code, i am able to run the app in emulator but as soon as i capture an image, the application crashes .
    According to logcat and my understanding, the application is not able to get TessBaseAPI. It throws an java.lang.exceptionInInitializerError. E/AndroidRuntime(547): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load lept: findLibrary returned null

    Please help. Thanks.

    1. I’m facing the same error as sacsha, I already added the tess-two as library project, but still get that error, and I also try it to OCRTest sample project and it give the same error. I’ve try to run it in windows and mac and the error still the same, please help

  76. Hey Gautam, I get this error when typing android update project --path in command: "Error: Missing argument for flag --path". What’s wrong?

  77. Hey Gautam, your tutorial is awesome and it runs perfectly for me.
    But the output results are like 50%. 🙁
    Can you please tell me other ORC libraries other than Tesseract to get text from images?

    1. You might want to use the Google Docs API for OCR. Never tried implementing it myself though, but it does produce better results. 🙂

    2. You can improve results dramatically by allowing the user to crop the image (if that fits with your model), also, try adding white/blacklisted characters.

    3. One thing more, every time when I install .apk file on a new android phone, I have used to place eng.traindata separately after installation. Is it possible that my akp file includes eng.traindata and when I install my apk it will automatically copy this file to a separate folder? Any helpful link?

    4. Muhammad you need to copy it from the assets directory and onto your SD card when you load the app. That way, when a user installs the app and opens for the first time, the traineddata file gets deployed onto the SD card ready for use.

      Black/whist listed characters allows you to ignore particular characters and look for others

  78. Hi guys, I try to configure it on windows 7 using Cygwin, I can build with ndk-built but I have this error
    -bash: android : commande introuvable when I try android update project --path
    Despite I set environment variables for the sdk, the error persists.
    I need help please. Thanks in advance!

    1. You have to add the SDK’s tools/ and platform-tools/ directories to your PATH.

  79. I have succesfully build the tess-two library on my ubuntu 12.04. But I still get force close error from my app. Do I have to use the leptonica processing library for rotating etc? Could you send me the full code that running your site? Thanks for your help!

  80. I am using your simple android app, I want to modify the program so that an image should be stored in gallery of a mobile – just taking the image and getting the text from the image. Please reply as soon as possible. Thanks!

  81. Is it okay if I build the source code you provided on a windows laptop or for that too I need to do it on a linux machine?

  82. Okay one more question – I downloaded the source code of ur simple OCR app. If i am directly using your code then I dont need to do that ndk-build and all those steps right? Sorry but i am new to this… would be glad if you could reply asap as this will be my project. Thanks. 🙂

  83. When I try to import the project, it is showing some problems –
    "FROYO cannot be resolved or is not a field ReadFile.java /tess-two/src/com/googlecode/leptonica/android line 47 Java Problem"
    also "ERROR: resource directory '/home/akhila/Desktop/android downloads/rmtheis-tess-two-071820a/tess-two/res' does not exist"
    I have imported only the tess-two project.

  84. Hi there Gautam! I’m student from Taiwan. First thank you for writing this page.

    I have one question about initializing Tesseract OCR engine for Chinese (traditional). I can run this app on my device with English but chinese is not working without fail. “Please Wait initializing Tesseract OCR engine for Chinese (traditional)” then close.

    Could you tell me how to fix this? Thanks!

    1. It could be a RAM problem, because the Chinese model is bigger. Does it work on the emulator?

    2. Hi Gautam,
      I’m trying to build Hindi OCR android app.
      You said you made it work with Hindi. Do we need to use .cube files also for Hindi language ? If yes, then how are we making use of .cube files and where to put these files ?

      Thanks in advance

  85. I am beginner for android platform. Please Can you explain me what is the technology you have used for image processing when using OCR. I mean histogram analyse, edge detection like that. Or please just give me road map how this is working. Have you used the match lab for this implementation?

    1. You can Google on how does Tesseract work, there are some presentations and PDFs which will help you learn on the how-to. 🙂

  86. Hi Gautam,

    I am working on tesseract on linux. Tesseract doesn’t provide any support for OCRing image.
    Can you please tell me how this support can be provided in tesseract? Do we need to write any new API or is there any existing API in tesseract code which can be modified to support image?
    Do you know any API which was implemented for other OCR technique for images and the same can be included into tesseract?
    Thanks, Anoop.

  87. Hi Gautam, you are doing a mind blowing job! Am a newbie working on OCR right now.

    I have built ndk in windows itself generated some 250 mb and .so files ina armeabi, armeabi-v7a and x86 folders and respective liblept and libtess.so. But I get ExceptionInInitializer error – "06-03 12:22:56.745: E/AndroidRuntime(15568): Caused by: java.lang.UnsatisfiedLinkError: Library lept not found"

    Can you please help me out?

    1. You’re getting that error because the libraries are not available when your application runs.

      Make sure you have them imported as library projects in your IDE and are available at application runtime (tess-two that is)

  88. Pingback: Tesseract OCR on Android is easier if you Maven-ise it, works on Windows too… | James Elsey
  89. I am getting following error when app is running.

    Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI

    It is getting in this line

    baseApi = new TessBaseAPI();

    It looks like unable to initialize TessBaseAPI.
    What can I do for this? Is there any special OCR configuration ?

    1. Hey Dharshana,

      Is there anything more printed out in your logcat?

      Make sure that you’re IDE is placing tess-two as a library project, and that it is actually getting deployed to the device.

      Also make sure that the traineddata files are there, and are not secretly there but with 0 bytes (that caught me out).

      Since you can’t even “new up” the TessBaseAPI, I’d wonder if its an issue with the tess-two library dependency not being available at runtime..

  90. Hi james, I have the same problem, I placed tess-two as a library project and added it to my ocr project but I still have this error:

    06-08 09:31:15.450: D/asset(252): Data exceeds UNCOMPRESS_DATA_MAX (1926792 vs 1048576)
    06-08 09:31:15.450: E/SimpleAndroidOCR.java(252): Was unable to copy fra traineddata java.io.IOException
    06-08 09:32:41.850: V/SimpleAndroidOCR.java(252): Starting Camera app
    06-08 09:32:44.910: W/IInputConnectionWrapper(252): showStatusIcon on inactive InputConnection
    06-08 09:32:52.302: D/dalvikvm(252): GC freed 1138 objects / 77784 bytes in 222ms
    06-08 09:32:53.070: I/SimpleAndroidOCR.java(252): resultCode: -1
    06-08 09:32:53.390: V/SimpleAndroidOCR.java(252): creation of the bitmap
    06-08 09:32:53.450: V/SimpleAndroidOCR.java(252): Orient: 0
    06-08 09:32:53.460: V/SimpleAndroidOCR.java(252): Rotation: 0
    06-08 09:32:53.460: V/SimpleAndroidOCR.java(252): could correct orientation
    06-08 09:32:53.470: V/SimpleAndroidOCR.java(252): could correct orientation
    06-08 09:32:53.470: V/SimpleAndroidOCR.java(252): Before baseApi
    06-08 09:32:53.480: D/dalvikvm(252): Trying to load lib /data/data/com.datumdroid.android.ocr.simple/lib/liblept.so 0x44e8cb20
    06-08 09:32:53.830: I/dalvikvm(252): Unable to dlopen(/data/data/com.datumdroid.android.ocr.simple/lib/liblept.so): Cannot load library: link_image[1721]: 30 could not load needed library 'libjpeg.so' for 'liblept.so' (load_library[1051]: Library 'libjpeg.so' not found)
    06-08 09:32:53.830: W/dalvikvm(252): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/googlecode/tesseract/android/TessBaseAPI;.
    06-08 09:32:53.840: D/AndroidRuntime(252): Shutting down VM
    06-08 09:32:53.840: W/dalvikvm(252): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
    06-08 09:32:53.850: E/AndroidRuntime(252): Uncaught handler: thread main exiting due to uncaught exception
    06-08 09:32:54.100: E/AndroidRuntime(252): java.lang.ExceptionInInitializerError
    06-08 09:32:54.100: E/AndroidRuntime(252): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:247)
    06-08 09:32:54.100: E/AndroidRuntime(252): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:164)
    06-08 09:32:54.100: E/AndroidRuntime(252): at android.app.Activity.dispatchActivityResult(Activity.java:3828)
    ...
    06-08 09:32:54.100: E/AndroidRuntime(252): at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:47)
    06-08 09:32:54.100: E/AndroidRuntime(252): ... 15 more
    06-08 09:32:54.140: I/dalvikvm(252): threadid=7: reacting to signal 3
    06-08 09:32:54.444: I/dalvikvm(252): Wrote stack trace to '/data/anr/traces.txt'
    06-08 09:32:57.100: I/Process(252): Sending signal. PID: 252 SIG: 9

    I need any help. Thanks in advance.

    1. Ouch, you’re getting all sorts of horrible errors there!

      Firstly you got an IOException trying to copy the traindeddata file over, is that the right filename? Do you have external storage write permissions? As a dirty hack, I’d copy it over manually now via DDMS file explorer, and come back and fix that later, its not ideal, but will get you progressing.

      Next it complains about *.so files being missing, and subsequent errors are probably stemming from this. Looks to me like the library project is not there, as your app can’t find files from it.

      If you’re a fan of Maven, I’d seriously recommend trying to use that as its library management is pretty good, I wrote a quick tutorial here:

      http://www.jameselsey.co.uk/blogs/techblog/tesseract-ocr-on-android-is-easier-if-you-maven-ise-it-works-on-windows-too/

  91. Hi James thanks for reply, but there is no other solution to make it working without maven, I try with android 2.2 but I have the same problem. I need help please. Thanks in advance

  92. I am using windows. I have compiled and build project successfully. But it is not working. When running and it says
    Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI.

    I did testing after commented TessBaseAPI initializing line then it is working and showing UI with square. But it was failed when getting the image snap from the camera. Then it says no OCR plugging.

    I am using windows. Still I can’t understand what the usage of ndk-build
    is. What is usage of it? Do I need to build NDK using cygwin. I have configured test-two project as well.

    Is it possible run this in windows with Cygwin or do I need to use Linux?
    Please help me because this is very critical for me now.
    I t would be highly appreciated if you can help me to run this project.

    1. Hi dharshana, yes it is possible to run this on windows. I have successfully build tess-two on windows with cygwin. Then I use android 2.3 emulator – I don’t have errors but I have a bad result.

  93. I have used NDK and tried to build test_two project from Cygwin. While running NDK build command I have got following error. Please help me.


    Compile thumb : lept <= pix4.c
    ...
    Compile++ thumb : lept <= jni.cpp
    Prebuilt : libgnustl_static.a <= /sources/cxx-stl/gnu-libstdc++/libs/ armeabi/
    SharedLibrary : liblept.so
    F:/MSC_project/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/wi ndows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androidea bi/bin/ld.exe: ./obj/local/armeabi/libgnustl_static.a: No such file: Permission denied
    collect2: ld returned 1 exit status
    /cygdrive/f/MSC_project/android-ndk-r8/build/core/build-binary.mk:369: recipe fo r target `obj/local/armeabi/liblept.so' failed
    make: *** [obj/local/armeabi/liblept.so] Error 1

    1. I am glad to say, it was possible to build test_two project from NDK build without errors. I will do rest in next day and update you. The issue was my laptop folder permission issue. But I had to work with this issue until yesterday late night around 3 am. (:

  94. I need know how to setup base language and target(translating) language. I mean where to add Tesseract libs. I need to setup base language as Sinhala and translating (target) language is English. Is it possible? Then how can I do that? Please help me.

    1. hey Dharshana,

      You have 2 very distinct requirements there, I would seriously recommend splitting that work out and trying to do one thing at a time.

      First off, you need to get tesseract working with your target language. Once you can get that to log out the text, then you can begin to look at the translation (there are google APIs for that, dead easy to use)

      What is Sinhala? You can find the traineddata files for all the supported languages on the tesseract site here :
      http://code.google.com/p/tesseract-ocr/downloads/list

  95. Hi James Elsey

    Yes I have 2 requirements for this.

    I need to read Sinhala notice board or newspaper text from mobile phone and translate to English.

    Sinhala is the language using in Sri Lanka.

    My objective is Sinhala text translates to English.

    Please advise me where I have to setup application base language as Sinhala.

    Regards
    Dharshana

  96. $ ndk-build
    Install : libjpeg.so => libs/armeabi/libjpeg.so
    SharedLibrary : liblept.so
    E:/AndroidStuff/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/libgnustl_static.a: No such file: Permission denied
    collect2: ld returned 1 exit status
    /cygdrive/e/AndroidStuff/android-ndk-r8/build/core/build-binary.mk:369: recipe for target `obj/local/armeabi/liblept.so' failed
    make: *** [obj/local/armeabi/liblept.so] Error 1

    1. Thanks for replying! I have infact used the latest code. Can you please try to compile it on a Windows machine and see if it works?

    2. It works fine on Windows 7 but I’m not sure about Cygwin. Do “ndk-build clean” and try again without Cygwin. If you see references to “libjpeg.so” then you’re using old code.

    3. It is working fine in windows 7. I have done everything correctly, Cygwin build also worked.

  97. Hi, very nice Tut,

    I am on a Mac and have run the ndk-build ok.

    but

    android update project --path .

    Fails with
    Error: The project either has no target set or the target is invalid.
    Please provide a --target to the 'android update' command.

    what is this trying to do and any tips for fixing it
    Thanks

    1. I had a look at project.properties

      cat project.properties

      android.library=true
      # Project target.
      target=android-15

      and so I try

      android update project --path . --target android-15
      Error: Target id ‘android-15’ is not valid. Use ‘android list targets’ to get the target ids.

      no luck cus i dont know what i am doing

    2. If you have problem with command:

      android update project --path .

      Put in terminal to check ID of your target:

      android list targets

      Then put:

      android update project -t  --path .
  98. Hi Gautam
    I did try out with your points to creating tess-two project. I did even import to Eclipse, but when I add this project as library and when I try to run using android emulator I get exception as in emulator as
    W/PackageManager(58): Failed to cache package shared libs
    W/PackageManager(58): java.io.IOException: Couldn't create cached binary /data/data/com.uni.demo/lib/libtess.so in /data/data/com.uni.demo/lib
    W/PackageManager(58): at com.android.server.PackageManagerService.cacheNativeBinaryLI(PackageManagerService.java:3771)
    ...
    W/PackageManager(58): Package couldn't be installed in /data/app/com.uni.demo-1.apk

    Looking forward to your reply.
    thanks.

    1. Hi I did solve the exception that was coming in the project and I totally built it on windows. One more question how to set an area(which is expandable and reduce able) to capture the text.
      Looking forward to your reply.
      thanks.

    2. You’re best bet is to allow the user to crop the image, at least that way you can be certain you’ll only OCR the targetted area and not pick up other things that you’re not interested in.

  99. Hi

    Please can u help me to find where I have to put “tesseract-ocr-3.01.osd.tar.gz” file in the “rmtheis-android-ocr-1e83e96” project. I need to use this application without downloading any data from the internet.

    thanks

    1. You can write some code to install it from assets/ or you can run without OSD using PSM_AUTO.

    2. In addition to that I need to know where I have to put “tesseract-ocr-3.01.eng.tar.gz” file in the project.

  100. I cant understand how to update Path variables as it does not expand in the troubleshooting section.can u put it in the comments plz

  101. Thank you for the replay earlier about changing the language, I tried what you said but the program just shuts down without any warning. I’m trying to make the program read arabic but always the same thing. Here is my logcat if you can help I’d be grateful

    06-16 15:41:09.001: I/DEBUG(31): beac8eb4 66206e69
    06-16 15:41:10.171: D/Zygote(33): Process 696 terminated by signal (11)
    06-16 15:41:10.171: I/ActivityManager(70): Process com.datumdroid.android.ocr.simple (pid 696) has died.
    06-16 15:41:10.181: I/WindowManager(70): WIN DEATH: Window{409c3ec0 com.datumdroid.android.ocr.simple/com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity paused=false}
    06-16 15:41:10.191: I/WindowManager(70): Setting rotation to 0, animFlags=1
    06-16 15:41:10.201: I/ActivityManager(70): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=17}
    06-16 15:41:10.981: W/IInputConnectionWrapper(452): showStatusIcon on inactive InputConnection
    06-16 15:41:12.721: D/dalvikvm(70): GC_EXPLICIT freed 39K, 60% free 4181K/10375K, external 3125K/3903K, paused 75ms

  102. Good Day Gautam!

    I have successfully solved the error “./tess-two/res’ does not exist”. So I tried running the Simple OCR app you made as my guide in making my own. When I tried to run it as Android Application, a window will appear saying “Android library projects cannot be launched”

    Is that okay? Will it be running successfully on a device?
    I do not have any android phone with me at the moment that’s why I’m using the emulator.

    1. You have check Simple OCR as a library.
      Only Tess-two must be a library, try to check that and it might work.

  103. Please help me
    I already have the tess-two ‘s jar and so and added them into my project.
    when the AP runs to the code “baseApi.setImage(bitmap);” I got the errors as below:

    W/dalvikvm(20016): No implementation found for native Lcom/googlecode/tesseract/android/TessBaseAPI;.nativeSetImageBitmap (Landroid/graphics/Bitmap;)V
    06-28 05:57:03.080: W/dalvikvm(20016): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    06-28 05:57:03.206: E/AndroidRuntime(20016): FATAL EXCEPTION: main
    06-28 05:57:03.206: E/AndroidRuntime(20016): java.lang.UnsatisfiedLinkError: nativeSetImageBitmap
    06-28 05:57:03.206: E/AndroidRuntime(20016): at com.googlecode.tesseract.android.TessBaseAPI.nativeSetImageBitmap(Native Method)
    06-28 05:57:03.206: E/AndroidRuntime(20016): at com.googlecode.tesseract.android.TessBaseAPI.setImage(TessBaseAPI.java:246)
    06-28 05:57:03.206: E/AndroidRuntime(20016): at com.besta.app.camdict.CamDictActivity.ocr(CamDictActivity.java:168)
    06-28 05:57:03.206: E/AndroidRuntime(20016): at com.besta.app.camdict.CamDictActivity$ButtonClickHandler2.onClick(CamDictActivity.java:76)
    06-28 05:57:03.206: E/AndroidRuntime(20016): at android.view.View.performClick(View.java:3511)
    ...
    06-28 05:57:03.206: E/AndroidRuntime(20016): at dalvik.system.NativeStart.main(Native Method)

    1. What jar? Follow the instructions: The project is added as a library project, not as a jar.

    2. It’s tess-two.tesseract3.01-leptonica1.68-LibJPEG6b.jar
      The so files and jar are compiled by someone else.
      The project “tesseract-android-tools” has been added as a library.And the tessdata has coped into SDcard.

  104. Hi,
    So i followed all the steps and even updated my PATH variables in my .bashrc file and extracted the tesseract and did ndk-build but i am getting stuck on the android update project –path step ..can anyone explain to me what am i exactly supposed to type here .. i did type android update project –path /home/mustafa/Downloads/tess/tess-two but it showed me an error which says Missing argument for flag

    Thanks.

  105. Please can anyone explain why following all file are using in the application? It would be nice if it can be explained file by file. Why it is using what will happen if I do not use it likewise.

    eng.cube.bigrams
    eng.cube.fold
    eng.cube.lm
    eng.cube.nn
    eng.cube.params
    eng.cube.size
    eng.cube.word-freq
    eng.tesseract_cube.nn
    eng.traineddata
    osd.traineddata

    These are downloading when app is restarting at first time.

  106. Hi rmtheis

    In the file OcrInitAsyncTask.java

    there is an comment and the code
    // Check assets for language data to install. If not present, download from Internet
    try {
    Log.d(TAG, "Checking for language data (" + destinationFilenameBase
    + ".zip) in application assets...");
    // Check for a file like "eng.traineddata.zip" or "tesseract-ocr-3.01.eng.tar.zip"
    installSuccess = installFromAssets(destinationFilenameBase + ".zip", tessdataDir,
    downloadFile);

    I tried with adding files in assets folder rather than to download from the internet.
    But this is not working. Tried with debugging and gives me back as file not found. Any code help on this would be useful.thanks.

    1. Just write the file transfer method and try transfer required files from the assets folder to application. I also did that. You can see the sample code in Simple-Android-OCR project.

  107. The log cat i have got:

    07-13 15:55:30.424: E/AndroidRuntime(26781): java.lang.ExceptionInInitializerError
    07-13 15:55:30.424: E/AndroidRuntime(26781): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:217)
    07-13 15:55:30.424: E/AndroidRuntime(26781): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:140)
    07-13 15:55:30.424: E/AndroidRuntime(26781): at android.app.Activity.dispatchActivityResult(Activity.java:3890)
    ...
    07-13 15:55:30.424: E/AndroidRuntime(26781): at com.googlecode.tesseract.android.Te

  108. I want to design an app as a project,so
    I downloaded Simple-Android-Ocr project (thnx a lot for it Gautam)but now when i went to its Java Build Path->Android Dependencies->tess-two.jar.Here it shows the path of tess-two.jar as=E:\AndroidProject\tess-two\bin(missing)
    plz could any one tell me how to solve this missing issue?
    and
    (there is no error marking seen for the project in the Project Explorer but a red exclamation mark,Why?)

    1. You might want to try asking this question on StackOverflow.

      Be sure to leave as many details as you can, including exactly how you built the library.

  109. Hi Rmtheis && Gautam

    I have completely run the your simple and advance applications and it was successful. I am doing a project for my MSC which relates to this area. I will do some improvement with OCR. I will update u when it will success.

    Thank you very much for your kind support and maintaining this blog.

    Regards
    Dharshana

  110. Okay, this will blow your mind. I’ve achieved Object/Image Recognition, in an app. I won’t even begin to go into the code.. it was ridiculous. Basically I use algorithms I developed to scour the net and do many calculations:)

    Check it out, particularly the video, it scared me when I first started debugging it!!

    Computer Vision!!!! Finally! Android Eye is the first Object Recognition App. Take a picture of any object, and Android Eye will tell you what it is. Computer Vision. Image Recognition Technology (IRC). Take a picture of a car… Android Eye will tell you the make and model of the car. Take a picture of a foreign t-shirt label… Android Eye will tell you the brand, and where the shirt is from. Take a picture of a tree… a ball… a person… the results are endless. This is the Beta version, it works very well, particularly with vehicles, products, brands, and well-known “things”:) Software that does this is usually only available to government agencies and research facilities. I will eventually release the code “open source”, once it’s been on the market for a bit:)

    Enjoy, and learn with it:) Ideal for visually impaired persons. Ideal for identifying vehicles or other manufactured items including computers, phones, or anything you would like a name for, a make or a model:)

    https://play.google.com/store/apps/details?id=com.davecote.androideyes

    http://www.youtube.com/watch?v=YEArrqAoL8A

    Dave:)

  111. Hi Gautam,

    I got the demo working, all the way up to taking a picture. But when I try the OCR, the app closes without warning.

    In the catlog, I see this:

    07-31 23:35:49.745: I/DEBUG(1251): pid: 32060, tid: 32060 >>> com.example.ocrdemo <<<
    07-31 23:35:49.745: I/DEBUG(1251): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
    07-31 23:35:49.745: I/DEBUG(1251): r0 0000009e r1 afd42428 r2 afd435d8 r3 00000000

    This happens at or just before the line:

    baseApi.init(DATA_PATH, lang);

    Do you have any idea what is the matter here?

    Thanks in advance,

    Wim.

  112. Hi Gautam i am trying to make an ocr based application in android using these instructions but getting error when trying to run this command “cd /tess-two ndk-build android update project –path . ant release
    ” . The error is “‘ndk-build’ is not recognized as an internal or external command,operable program or batch file” any help will be appreciated .thank you ..

  113. For me libjpeg.so could not create. I’m following as per your instruction would you please help me.

  114. Hi,

    I am thinking to develop an open source mobile application to read license plates in order to retrieve the number with the cell phone. I mean, with the cell phone I take a picture of the car (front or back), and then the application performs an OCR analyzes in order to retrieve the matriculation number. Once I have the text in the application, I could realize other operations, such as report the license plate to a Police central via SMS.

    I saw that your project performs OCR on Android, and this is a starting point for my idea, but probably this is the most important part because of the OCR algorithm. I would like to know if your project could really help me with the idea, and also, it would be very interesting to know your opinions.

    Finally, taking what you say in the profile, are you interested in being part of this idea I am proposing?

    Thanks, and good work.

  115. Hello, I’m trying to build this library on Windows Vista. Reading these posts, I’m realizing that building tesseract will likely not be a possibility for me. Is there a place where I can download the already built library project for eclipse? I’m leaving for MIT in two days so I won’t be able to work on this anytime soon. Thanks in advance

  116. For example I have an image in which has the number in it. Is it possible to read the number from the image? Even if the image is black/white or color image. Can you please suggest any ideas?

  117. I have followed all the steps mentioned above and its not showing any errors. But at the runtime i am getting the ExceptionInInitializerError while initializing the TessBaseAPI object. Can you pls help me with that problm? Thank you.

  118. Hi Gautam.

    I tried your code for recognizing the text from the image the code and results are fine, but when I try with the image that have numbers, the app mistankenly gives the values wrong sometimes. Can you please suggest any solution?

  119. Hello Gautam. I’ve compiled the code completely on my Windows 7, there’s no problem, despite that I never get reasonable results from reading my pictures. Do you know some reasons for this?

  120. Heya i’m for the first time here. I found this board and I find It truly useful & it helped me out much. I hope to give something back and help others like you helped me.

  121. Gautam,

    Thank you very much for this blog. I am just a beginner on Android development. I was able to set up the project in my Eclipse and able to run the simple android ocr app.

    I had to provide the target number and also had to re-install the JDK and provide proper JAVA_HOME variable while doing step#2. Other than that the step step instruction was very helpful.

    NB: I am using windows7 OS and it worked properly.

    Way to go buddy!!

    Santhosh
    Thank you again!!

  122. Hi Everybody
    I run the ndk-build command and getting error
    please give me response this

    /cygdrive/d/android-ndk-r8b/ndk-build
    Cygwin : Generating dependency file converter script
    Compile thumb : lept <= open_memstream.c
    Compile thumb : lept <= fopencookie.c
    Compile thumb : lept <= fmemopen.c
    Compile++ thumb : lept <= box.cpp
    In file included from jni/com_googlecode_leptonica_android/box.cpp:17:0:
    jni/com_googlecode_leptonica_android/common.h:22:24: fatal error: allheaders.h: No such file or directory
    compilation terminated.
    /cygdrive/d/android-ndk-r8b/build/core/build-binary.mk:255: recipe for target `obj/local/armeabi/objs/lept/box.o' failed
    make: *** [obj/local/armeabi/objs/lept/box.o] Error 1

    1. Hi Irfan; how did you manage to solve the allheaders no such file error? Having that here, using android studio.

  123. Thanks Gautam, I am new to both Android and OCR processing, but your tutorial was significant great on my first move on them. Thanks a lot!
    By the way I have done this tutorial by Eclipse on Window 7 with the help of cygwin and apache-ant-1.8.4.
    Let’s work hard together for a bright future, all the best! 🙂

  124. Hi Gautam,

    I want to use leptonica tools in android for document image analysis . Any idea how to do that ?

    Thanks in advance

    1. Me too, especially for id cards. I’ve trained my own tesseract data, and seen a big improvement in recognition, but still no idea for how to specifically analyse the cards….

    2. just prepare a sample photo of your own font, open the command line, and follow the instructions on that site carefully. it’s no that difficult. you don’t need the understand the site completely, you will understand it gradually, don’t worry

  125. Hi all,

    I have followed this tutorial accurately. However, the line
    TessBaseAPI baseAPI = new TessBaseAPI();

    causes my Android app to shut down unexpectedly. Upon looking at logcat, it says that this caused because of missing Library lept. The exact line is:

    10-16 16:24:16.406: E/AndroidRuntime(389): Caused by: java.lang.UnsatisfiedLinkError: Library lept not found

    I have imported all the relevant libraries, including com.googlecode.tesseract.android.*
    com.googlecode.leptonica.android.*

    Any ideas what could be the reason and how to solve it?

    Thanks!

    1. Maybe you can go to the tess-two library, and see if you can find the file liblept.so in there? If not, you need to ndk-build your jni source

  126. hi i am not able to run the code on windows xp i have downlaod cygwin and ndk 1.8 i am getting this error ExceptionInInitialiazer

    please help me.

  127. Hi,I have written an android application using tesseract-ocr after reading your post.I’ve to finished it but I need the user to edit the captured bitmap image for good result.Here is a question about it ,please help!This is the last step to publish my application.Good luck! http://stackoverflow.com/q/12931603/1665807

  128. Thank You for such a wonderful tutorial. This works on Windows. No need of Cygwin. I used GitBash. But I wanted to ask that how do we increase accuracy?? I mean this app when run on mobile gives correct text once in 10 times.

  129. Hi. When I run the Robert Theis app. (Intermediate+). I get “Could not initialize the camera. Please restart the device’. What could be the error? Any help would be appreciated 🙂

  130. Hello. I’ve successfully compiled and run TessTwo in Eclipse Indigo on Windows for my Android app. It works ok with a short line of text (just one misread of a 2 as a Z). But if I increase the length of the text, at some point GetUTF8Text will crash my app. So, I’m trying to debug the jni native C code. I’ve compiled the C source (a long process), but still can’t get the debugger to stop ignoring my breakpoints in the C code. Can anyone offer any ideas? Thanks!

    1. At what point does it crash? Large images can crash the emulator if you don’t have enough RAM defined.

    2. Thanks for responding. I haven’t been able to debug any deeper than the nativeGetUTF8Text() call in the Tessbaseapi.class file. I can’t get a responsive breakpoint in the Tessbaseapi.java file at all. If I F5 on the GetUTFText call while debugging in Eclipse, the debugger will report only:

      TessBaseAPI.nativeGetUTF8Text() line: not available [native method]

      Still trying to get native debugging working properly in Eclipse. Haven’t even touched tessbaseapi.cpp yet.

      In LogCat, using a ‘TessBaseAPI.java’ Log Tag filter (do you suggest any other?), I see only the following series of (probably irrelevant) messages:

      11-04 23:42:47.505: D/TessBaseAPI.java(4075): finalize(): NOT calling nativeFinalize() due to premature garbage collection
      11-04 23:42:47.505: D/TessBaseAPI.java(4075): finalize(): calling super.finalize()

    3. Well, trying to debug the JNI code sounds like an exercise in frustration. Does it give a SIGSEGV message when it crashes?

      I don’t see this kind of crash in my android-ocr project.

    4. Yes, it’s frustrating. Did/do you ever have to debug your jni code? If so, how? No, I haven’t seen that SIGSEV message. In Log Cat? If so, what filter so as to isolate it from the other messages pouring into Log Cat?

  131. Hi,
    Great guide! finally got it working! 🙂
    The only problem is that I get very bad results. The engine does not recognize most images I put threw it. I tried taking the pictures with the phone camera, and I tried downloading images from the web.
    On both cases I get very very bad results. I even used the android ocr application and the simple application. Got bad results from it too.

    Any ideas on how I can get better results??

    Thanks!!

    1. read through this blog and you’ll find:
      1.cut the image util it contains only the text zone
      2.augment the quality of your image with thresholding and many others means

  132. Hello , I am a student in Jordan University Of Science And Technology (JUST) . Thanks Guatum for your posts , but I have a problem when running sentence translation (ocr) application in my laptop which work on Ubuntu 11.04 , when I download the project it is run but the emulator give me message say that (the application has been stopped unfortunately ) and I don not know why . Please help me because the due date of this project is next week.

  133. master Gautam. can you make a tutorial on how to put movable borders on capturing words just like on the video

  134. @xinton
    read through this blog and you’ll find:
    1.cut the image util it contains only the text zone
    2.augment the quality of your image with thresholding and many others means

    Please elaborates these two steps clearly by code as well as possible…
    Thank You

  135. Can I use any library for translation other than google API? Because when I import the application the linked to google API library translation give an error.

  136. Hi Gautam iam student in faculty of computer and informatics and I want to use tesseract with android these steps you have written is good but there is exception thrown is classDefNotFoundException event the tessBaseApi.class?

  137. Hello Gautam hope you are doing well. Actually i want develop an application using OCR and on searching i found your blog. I have downloaded your tess-two-master tree from github and trying to run it. I am running it on Windows XP that’s why I have installed Cygwin and NDK and have set their path into the PATH variable. But on giving the ndk-build command from command prompt I’m getting this error:-

    /usr/bin/sh: -c: line 1: syntax error: unexpected end of file make: *** [obj/local/armeabi/objs/lept/src/src/adaptmap.o] Error 1

    I have searched this file in the tess-two-master folder but not found any adaptmap.o file.
    Please help me on this.
    Thank you in advance.

    1. The Android NDK is compatible with Windows XP, so I suggest trying the build directly under Windows and not using Cygwin.

  138. It work fine on windows 7, CYGWIN isn’t needed. I just had a little problem with my antivirus(COMODO) and I had to deactivate Defense+.

    1. Can you tell me how you got working windows?
      Mine built ok but when i try to do a ocr capture the app forces close

  139. Hi Guys, Hi Gautam.

    Good day.

    We just started our thesis and it’s a Signage & word Translator using OCR for Android.

    We already put the codes in Eclipse, compiled our scripts using leptonica and cygwin. Read all the steps, but we’re still getting errors.

    We can’t compile them properly.

    Listed in here are the errors we got:

    1. [2012-11-28 02:53:20 – tess-two] Android requires compiler compliance level 5.0 or 6.0. Found ‘1.4’ instead. Please use Android Tools > Fix Project Properties.

    2. [2012-11-28 02:53:21 – tess-two] Android requires compiler compliance level 5.0 or 6.0. Found ‘1.4’ instead. Please use Android Tools > Fix Project Properties.

    3. [2012-11-28 02:53:49 – tess-two] ERROR: resource directory ‘C:Usersgatewayandroid-sdkstess-twores’ does not exist

    4. [2012-11-28 02:58:06 – tess-two] ERROR: resource directory ‘C:Usersgatewayandroid-sdkstess-twores’ does not exist

    Please.. Please..
    Can you help us? 🙁

    Thank you..

    1. Right-click on the project name in Eclipse and choose Android Tools->Fix Project Properties.

      Then do Project->Clean.

  140. Thanks Gautam and Rmtheies for these great tutorial , i really appreciate your help god bless you.

    I did all the step then when run my application and capture an image it does but when i press ok after an image capture it fails .when i look at logcat shows:

    logcat:

    11-27 23:39:43.527: I/SimpleAndroidOCR.java(1317): resultCode: -1
    11-27 23:39:43.647: D/dalvikvm(1317): GC freed 1422 objects / 92160 bytes in 96ms
    11-27 23:39:43.927: V/SimpleAndroidOCR.java(1317): Orient: 0
    11-27 23:39:43.927: V/SimpleAndroidOCR.java(1317): Rotation: 0
    11-27 23:39:43.957: D/dalvikvm(1317): GC freed 169 objects / 39536 bytes in 33ms
    11-27 23:39:43.977: V/SimpleAndroidOCR.java(1317): Before baseApi
    11-27 23:39:43.977: D/dalvikvm(1317): Trying to load lib /data/data/sms.recieving/lib/liblept.so 0x44717aa0
    11-27 23:39:43.977: I/dalvikvm(1317): Unable to dlopen(/data/data/sms.recieving/lib/liblept.so): Cannot load library: link_image[1721]: 51 could not load needed library 'libjnigraphics.so' for 'liblept.so' (load_library[1051]: Library 'libjnigraphics.so' not found)
    11-27 23:39:43.977: W/dalvikvm(1317): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/googlecode/tesseract/android/TessBaseAPI;.
    11-27 23:39:43.987: D/AndroidRuntime(1317): Shutting down VM
    11-27 23:39:43.987: W/dalvikvm(1317): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
    11-27 23:39:43.987: E/AndroidRuntime(1317): Uncaught handler: thread main exiting due to uncaught exception
    11-27 23:39:43.997: E/AndroidRuntime(1317): java.lang.ExceptionInInitializerError
    11-27 23:39:43.997: E/AndroidRuntime(1317): at sms.recieving.ocrActivity.onPhotoTaken(ocrActivity.java:211)
    11-27 23:39:43.997: E/AndroidRuntime(1317): at sms.recieving.ocrActivity.onActivityResult(ocrActivity.java:133)
    ...
    11-27 23:39:43.997: E/AndroidRuntime(1317): at java.lang.System.loadLibrary(System.java:557)
    11-27 23:39:43.997: E/AndroidRuntime(1317): at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:47)
    11-27 23:39:43.997: E/AndroidRuntime(1317): ... 15 more
    11-27 23:39:43.997: I/dalvikvm(1317): threadid=7: reacting to signal 3
    11-27 23:39:44.007: I/dalvikvm(1317): Wrote stack trace to '/data/anr/traces.txt'

  141. Hey Gautam!

    I am trying to run the initial set of commands for tess-two..on windows7 command Prompt.
    For ndk-build am getting the following error:
    Android NDK: Could not find application project directory !
    Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
    E:\android-ndk\android-ndk-r8c\build/core/build-local.mk:130: *** Android NDK: A
    borting . Stop.

  142. To Meghna,
    I’m not sure that it will work or not. I worked in Linux. May i know where the tess-two is kept?

    you need to change directory first.(wrinting linux command, varies / or \ with this, may be)

    cd /home/*your account name*/AndroidApc/tess-two/

    /home/*your account name*/Documents/Android_NDK/ndk-build

    it may help.

  143. Good Day Gautam and rmtheis

    Can you help me solve this problem?

    BUILD FAILED
    /home/gateway/Downloads/tess-two-master/tess-two/build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var

    Thank you.

  144. Could someone please tell me what should I update the path variable as – for ant release command.

    I have downloaded ant, the path for that folder is E:\ant\apache-ant-1.8.4

  145. Why is it the SimpleOcr cannot be installed in my android phone? I tried to export it with unsigned application project to build apk.

    1. well , i have changed the trained data from eng(english) to hin (hindi) and in the code changed the letters accordingly.It previously performed well for english characters, but didnt turn up with results with hindi letters.
      Does
      String recognizedText = baseApi.getUTF8Text();
      have any issues with this??

  146. @rmtheis
    When I’m trying to export your ocr master why is this happening?

    proguard returned with error code 1. see console

    On the other hand @Gautam simpleOCR I can export it without any error considering the fact that I’m using both of your work on the same ADT?

    Please help me. Thank you so much!

    1. Thank you for the concern @rmtheis

      The console says:

      [2013-01-03 08:55:03 - OCRTest] Unexpected error while evaluating instruction:
      [2013-01-03 08:55:03 - OCRTest] Class = [android/support/v4/view/AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl]
      [2013-01-03 08:55:03 - OCRTest] Method = [newAccessiblityDelegateBridge(Landroid/support/v4/view/AccessibilityDelegateCompat;)Ljava/lang/Object;]
      [2013-01-03 08:55:03 - OCRTest] Instruction = [18] areturn
      [2013-01-03 08:55:03 - OCRTest] Exception = [java.lang.IllegalArgumentException] (Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate]))
      [2013-01-03 08:55:03 - OCRTest] Unexpected error while performing partial evaluation:
      [2013-01-03 08:55:03 - OCRTest] Class = [android/support/v4/view/AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl]
      [2013-01-03 08:55:03 - OCRTest] Method = [newAccessiblityDelegateBridge(Landroid/support/v4/view/AccessibilityDelegateCompat;)Ljava/lang/Object;]
      [2013-01-03 08:55:03 - OCRTest] Exception = [java.lang.IllegalArgumentException] (Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate]))
      [2013-01-03 08:55:03 - OCRTest] java.lang.IllegalArgumentException: Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate])
      [2013-01-03 08:55:03 - OCRTest] at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:287)
      [...]
      [2013-01-03 08:55:03 - OCRTest] at proguard.ProGuard.main(ProGuard.java:492)

    1. If your eng.traineddata is at

      /mnt/sdcard/tesseract/tessdata/eng.traineddata

      then you should write

      baseApi.init("/mnt/sdcard/tesseract/", "eng");

  147. I am stuck at the command:
    android update project –path .

    So I set the PATH to:
    C:\Users\SilverSand85X\Desktop\android-ndk-r8d;
    C:\adt-bundle-windows\sdk\tools;
    C:\Users\SilverSand85X\Desktop\OCR\tess-two-master;
    C:\adt-bundle-windows\sdk\platform-tools

    Am I doing it wrong?

    1. The ndk-build works on Windows 8.

      You don’t have to change your PATH, just type the command as is.

  148. I have followed all of the instructions that have been given gautam, but I still get erorr when the running on my phone. And this is my Logcat:

    01-27 19:08:36.182: E/AndroidRuntime(12957): FATAL EXCEPTION: main
    01-27 19:08:36.182: E/AndroidRuntime(12957): java.lang.ExceptionInInitializerError
    01-27 19:08:36.182: E/AndroidRuntime(12957): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:211)
    01-27 19:08:36.182: E/AndroidRuntime(12957): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:135)
    01-27 19:08:36.182: E/AndroidRuntime(12957): at android.app.Activity.dispatchActivityResult(Activity.java:4649)
    [...]
    01-27 19:08:36.182: E/AndroidRuntime(12957): at java.lang.System.loadLibrary(System.java:535)
    01-27 19:08:36.182: E/AndroidRuntime(12957): at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:47)
    01-27 19:08:36.182: E/AndroidRuntime(12957): ... 15 more

    Please, give me the solution because this is my final project. And sorry for my english.

  149. hey i downloaded ur project from github and imported it in eclipse
    when i press the ocr button in the app, the app is force closing it and in the logcat its givin fatal exception main
    plz help on this

  150. Hello,

    I’ve been training with tesseract.exe from the following Windows installation: (tesseract-ocr-setup-3.01-1.exe) in support of my Android app, which borrows from RM Theis’s work with the Tess-Two.

    It seems that running tesseract.exe with the ‘batch.nochop makebox’ option (to create a box file) is the ONLY way to obtain truly accurate character positions relative to the image. Back in my Android app code, running getUTF8Text() and then getCharacters() seems to produce character boxes that are not truly aligned with the image, but are aligned with how tess interpreted the word and sentence structure in terms of whitespace. I also notice that the text output of getUTF8Text() produces correct whitespacing, whereas the character boxes output of getCharacters() evidently does not (injecting too many spaces and even splitting up words to inject a space character).

    Can anyone explain this behavior? I was also wondering if I could invoke the makebox function in my Android app, so that I can display in near-realtime recognition quality feedback directly over the recognized characters themselves (using a semi-transparent Android overlay) and replacing the imaged characters with crisp artificial characters of the same font. Or if there is any other way to get those original character box positions within my app source code, I would love to know it.

    Thanks!
    Ted

  151. dear gautam i just want to add selectable region in my camera plz help me through this .i am not able to seperate selectable region code

  152. i have and error when building the ndk, this is the error: jni/../external/libjpeg/jidctfst.S: Assembler messages:
    jni/../external/libjpeg/jidctfst.S:66: Error: missing ‘)’
    jni/../external/libjpeg/jidctfst.S:66: Error: garbage following instruction — ` pld (r2,#0)’
    jni/../external/libjpeg/jidctfst.S:259: Error: missing ‘)’
    jni/../external/libjpeg/jidctfst.S:259: Error: garbage following instruction — `pld (sp,#32)’
    jni/../external/libjpeg/jidctfst.S:271: Error: missing ‘)’
    jni/../external/libjpeg/jidctfst.S:271: Error: garbage following instruction — `pld (ip,#32)’
    /cygdrive/d/Programming/Programs/android/android-ndk-r8d/build/core/build-binary .mk:267: recipe for target `obj/local/armeabi/objs/jpeg/jidctfst.o’ failed
    make: *** [obj/local/armeabi/objs/jpeg/jidctfst.o] Error 1

    i already checked this file and didn’t find that missing ‘)’

    can any one help ?

  153. Hi,
    I followed your instruction and advice here

    I download new eclipse, new ADT and SDK, and NDK r6b.
    then ndk-build, update and ant give:

    Compile++ thumb : tess <= resultiterator.cpp
    Compile++ thumb : tess libs/armeabi/libtess.so
    confusion@confusions:~/programovani/NoSpaces/eclipceWorkspace/OCR/tess-two-master/tess-two$
    .
    .
    .
    confusion@confusions:~/programovani/NoSpaces/eclipceWorkspace/OCR/tess-two-master/tess-two$ android update project --path . --target android-10
    Updated project.properties
    Updated local.properties
    Added file ./proguard-project.txt
    confusion@confusions:~/programovani/NoSpaces/eclipceWorkspace/OCR/tess-two-master/tess-two$ ant release
    .
    .
    .
    -post-build:

    release:

    BUILD SUCCESSFUL
    Total time: 7 seconds

    and then to the eclipse and import lib, but eclipse shows that there are erros screen 🙁
    and I downloaded your demo where is error because its not linked to the lib, because i can’t handle step 4.
    and this is the your project properities/android screen

    Can you help me or guide me some way please?

    1. So I find out the problem, and it was stupid error.
      But, is there any minimum api level? On my android 2.3.4 is going down, with -1 I think 🙂

    2. I tried to debug the Simple Android OCR (for begginers – demo) and got “Dalvik VM[localhost:8600]” on line 208
      TessBaseAPI baseApi = new TessBaseAPI();
      Why? please help!

  154. I can’t get this to work; my NDK is not being recognized. Is it not possible to download the tess-two project itself so I can import it into Eclipse? Would save alot of trouble.

  155. Why sometimes the recognized text is a bunch of random characters? I get this result even if there is no character in the picture. Also, I get the words right but at the start or at the end of the result show up some random characters.

  156. @rmtheis sir is it possible to create menu screen on your OCRtest? and i would to ask if how do the translation process work on your OCR?

    thank you in advance

    1. @rmtheis thank you so much, but there’s one thing. is there any way to use Google translate API for Free? I’ve just checked the latest version and its pricing is base on usage of character? please help.

      thank you again in advance
      i really appreciate your reply.

    2. @rmtheis the alternative translate API which is the bing translator do not work anymore? i guess have no other choice buy to use the google translate API?

      thank you

    3. @rmtheis does all i need to do is put the Client id & secret key and the translation will work?

  157. Everything works perfect, but I have one question. How can I show any message or something to inform user that searching is on progress? Now there is completly black screen during searching (generating recognizedText) and it looks like app is suspended.

    1. @James Esley:
      Okey, I did it. But still have few questions.
      Can you help me or give some advice?

      I wrote this:

      It is still working, but is there some other way how to pass the string to mainthread from onPostExecute, mayby via variable, I need to work with that before putting to editText.
      And how can I show something like splashscreen while recognizing, lunched from onPreExecute? via acitivty with picture?

      thank you for your help.

    2. Put the recognisation into an async task (so it doesnt lock main processing thread and induce an ANR), and then display an activity indicator that says “processing…”

  158. hi Gautam! im deo reyes, an IT student from UST, Manila, Philippines.

    im currently using your tutorial on building a basic OCR app on android. I also used rmtheis’ version. I have just one error which never showed up on any web search and troubleshooting sites such as stackoverflow. here is the error:

    The container ‘Android Dependencies’ references non existing library ‘C:UsersDeoDesktoptess-twotess-two.jar’

    I have compiled tess-two via cygwin successfully. What could be the problem? I have a feeling it is the next set of commands, but it doesnt work on my cygwin:

    android update project –path .
    ant release

    this is the only problem left so i could compile the project. please help asap. thank you very much 🙂

  159. I am compiling the tess-two using android NDK on windows 7 environment. I am getting following error:

    [obj/local/armeabi/libgnustl_static.a] Error 1 tess-two C/C++ Problem.

    Can you please help to solve this issue.

    Thanks
    Ajit

  160. hello,

    I have a problem. This is logcat log. Help me, please

    03-07 22:13:18.394: D/AudioSystem(26104): AudioSystem::get_audio_flinger() in at 53
    03-07 22:13:18.394: D/AudioSystem(26104): gLock get at 55
    03-07 22:13:18.394: D/AudioSystem(26104): before defaultServiceManager() at 57
    03-07 22:13:18.394: D/AudioSystem(26104): after defaultServiceManager() at 59
    03-07 22:13:18.394: D/AudioSystem(26104): service got at 63
    03-07 22:13:18.394: D/AudioSystem(26104): leave AudioSystem::get_audio_flinger() at 81
    03-07 22:13:18.394: D/AudioSystem(26104): AudioSystem::get_audio_flinger() in at 53
    03-07 22:13:18.394: D/AudioSystem(26104): gLock get at 55
    03-07 22:13:18.394: D/AudioSystem(26104): leave AudioSystem::get_audio_flinger() at 81
    03-07 22:13:18.444: W/MediaPlayer(26104): info/warning (1, 902)
    03-07 22:13:18.464: D/LanguageCodeHelper(26104): getOcrLanguageName: eng->English
    03-07 22:13:18.464: D/LanguageCodeHelper(26104): getTranslationLanguageName: es->Spanish
    03-07 22:13:18.574: W/dalvikvm(26104): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI;
    03-07 22:13:18.574: D/AndroidRuntime(26104): Shutting down VM
    03-07 22:13:18.574: W/dalvikvm(26104): threadid=1: thread exiting with uncaught exception (group=0x40ad0228)
    03-07 22:13:18.584: E/AndroidRuntime(26104): FATAL EXCEPTION: main
    03-07 22:13:18.584: E/AndroidRuntime(26104): java.lang.ExceptionInInitializerError
    03-07 22:13:18.584: E/AndroidRuntime(26104): at edu.sfsu.cs.orange.ocr.CaptureActivity.initOcrEngine(CaptureActivity.java:714)
    03-07 22:13:18.584: E/AndroidRuntime(26104): at edu.sfsu.cs.orange.ocr.CaptureActivity.onResume(CaptureActivity.java:371)
    03-07 22:13:18.584: E/AndroidRuntime(26104): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1236)
    [...]
    03-07 22:13:18.584: E/AndroidRuntime(26104): at java.lang.System.loadLibrary(System.java:535)
    03-07 22:13:18.584: E/AndroidRuntime(26104): at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:44)
    03-07 22:13:18.584: E/AndroidRuntime(26104): ... 17 more

  161. Hi Gautam, I was able to run your example in Windows plataform!

    Now,I would like to know if there is a method to increase the accuracy of the OCR. My app is not much accurate, has a trick like distance, size of letters.. something like that?
    Thanks!!
    André

    1. Hi André,
      Could you please, tell me what are the steps you taken to make it run on Windows platform. How you could able to compile the library and Add without getting errors ?
      Thanx !

      – Nisal_M

    2. Hi Nisal_M,
      I had some problems but I was able to run. I followed this steps:

      1- Install Android SDK
      2- Set in the path variable the path for android command
      3- Run the SDK Manager and install the Android plataform-tools
      4- Download and install the ADT Plugin for Eclipse
      5- Download and unzip NDK
      6- Set in the path variable the path for ndk-build command (you don’t need to install Cgwin)
      7- Enter in the tess-two directory and run the ndk-build command
      8- Run the command:
      android update project –path .
      7- Import the tess-two project to Eclipse and set it like library.
      8- Import the Gautam’s project and add the tess-two (now as a library).

      It worked for me!

  162. Hi, I would to use this OCR to ricognize license plates and i have a doubt: Does The tesseract try to form a word when ricognize a sequence of characters. I’m asking because my language is portuguese and i’m using eng.trainnedata and I observed that the application tries to do this? s it right?

    Thanks,

    André

    1. Hi James! I was thinking about crop the image, to reduce the time of processing. Now I’ll study how do that. Thanks!
      How can I set up the black/white list? Could You tell me please?
      Regards,
      André

    2. Thanks James! I’ll let you know!!!
      Now, I’m trying to use the por.trainneddata

      I unzipped the file and I put it in the same directory (tessdata) of eng.trainneddata. After I changed the line codes to adjust. When I run the app Logcat says me that was ocurred a javaIoException. In my mobile I saw the tessadata directory and the files .trainneddata with zero size. I’m making it in a wrong way?
      Thank you!

    3. Hi Andre,
      I’ve done the same for UK license plates, it was relatively easy once you set up a black/whitelist of the characters you expect.

      You may also need to crop the image so you just get the number plate and it doesn’t try to OCR things in the background, like road signs etc.

    4. I don’t have the code ready at hand, but from memory I believe you just set the black and white list on the tessBaseApi directly.

      For the white list I set A-Z0-9 and for the black list I just put in a load of special characters.

      Have a play with that and let us know if it improves the results, it certainly helped me (in combination with cropping)

  163. Hi guys i have a problem with ndk-build 🙁 please help me i researched so much in internet but i didnt find solution.
    My problem is in step ndk-build;
    .workspace/tess-two/jni/com_googlecode_tesseract_android/Android.mk:tess: LOCAL_MODULE_FILENAME should not include file extensions
    Android NDK: workspace/tess-two/jni/com_googlecode_tesseract_android/Android.mk:tess: LOCAL_MODULE_FILENAME must not contain a file extension
    /android-ndk-r6-crystax-2/build/core/build-shared-library.mk:30: *** Android NDK: Aborting

  164. Hi all!

    I was able to run this app example, and now I’m trying to change the eng.trainneddata to por.trainneddata but when I do that sometimes the followed message:
    Could not initialize Tesseract API with language=’por’.
    Can somebody help me, please?
    Thanks,
    André

  165. @rmtheis i dont know what happened but last week everything works fine. But this week when i try to export again the application and install on my device the application says. ” edu.sfsu.cs.orange.ocr” for close! Thank you for very much im advance

  166. Hi
    I would like to use this tesseract engine for reading printed equations ? Will it work on it ? Plus i am working on a Windows laptop . So is the entire process for linux or does it work for Win users too ??

  167. Greetings,

    Thank you very much for your code.

    I’m trying it and I want to know if the code of the point # 5 I must include it INTO the method: protected void onPhotoTaken() when I capture the image. (The code of the other page)

    thanks for your help

  168. Hey,
    I downloaded your application and when I capture the image with the camera an error pops up stating that the application stopped working, how can I solve this problem?
    Thank you

  169. I tried to build project put I found this error in step ant release

    BUILD FAILED
    F:\adt-bundle-windows-x86_64\adt-bundle-windows-x86_64\sdk\tools\ant\build.xml:7
    10: The following error occurred while executing this line:
    F:\adt-bundle-windows-x86_64\adt-bundle-windows-x86_64\sdk\tools\ant\build.xml:7
    23: Error running javac.exe compiler

    Total time: 3 seconds

    how can I fixed this error ?

    1. Check your java path. I was encountering the same problem. Resolved after setting JAVA_HOME path.

  170. Hi… I can run the example in windows platform… it work form me…
    now I’m in progress to make OCR app that will take picture and then translate it…
    thank you Gautam for sharing… 🙂

    1. Hi Seisy, Can you please tell me how you ran it from windows? I’m not able to do an NDK Build itself..I’m making an app which has the same module and I’m totally stuck in OCR. Would appreciate any tips and tricks for Windows

  171. I have tried this code this works fine. But some times app terminates with “process com.test (pid 654) has died” message after executing “baseApi.getUTF8Text();”

    Please help me where I am wrong.

  172. Greetings, Could I combine your project with other project for scan QR Codes?

    Is possible?

    Thanks

  173. Does this project work when I downloaded and import into Eclipse without any modify?

  174. I’ve tried Robert Theis’ Android OCR application (for intermediate+), i’ve managed to avoid downloading language and orientation data by putting “osd.traineddata.zip” and “tesseract-ocr-3.01.eng.tar.zip” in assets folder. However, the uncompressing of language data went successfully but uncompressing of the orientation and script complete percentage stays at zero, and it finishes with an error about connecting to the internet, and the Log Cat shows “untar failed”. But if i restart the app it loads without any errors and the Log Cat shows that the copy of the traineddata went successfully despite it shows that it failed the first time the application started, i would be so grateful for any help :).

    Thanks in advance,
    Omar Mohi.

  175. Hi i am getting this error
    Could not initialize Tesseract API with language=eng!
    can anyone help me soon?

  176. How can we do the same project in Windows ? Can anyone tell me how to do an NDK Build in Windows? Looks like the whole world is using this link for their OCR,and I’m not able to do even the first step 🙁

    1. Thanks for responding ! I’m using NDKr8 and Eclipse Juno. I tried Cygwin also, I’m getting a .so file, Build is not completed correctly

  177. Hey i am very thankful to you. coz you taught us a lot.
    i have a question i created an by modifying the provided app in tesstwo but when i try to read more then 3-4 line of text the app crashes can you tell me the reason.

  178. Hello,
    how i can do like the picture upon , select what square will be OCR
    kind regards

  179. Dear i have one more question.
    when i try to read a whole page in Emulator it works perfectly and displays the result accurately.but when i run this app on my mobile the app crashed.can you help me?

  180. thanks for your tutorial. I am trying to implement this one. I try to change the capturing image process with image which I uploaded. And, it’s not success. So, what is your problem in your opinion? Do this library only can recognize one line word picture?

  181. i m having a problem,whenever i run my ocr application the emulator stops on a white screen and doesnot display any my layout..

    1. I’m also having the same problem. The app gets closed after the picture is taken. Can anybody help to rectify this error?

  182. Anyone can help me, how to do an NDK Build in Windows?. This is the main task, anyone can tell me the procedure clearly for NDK build on window?..

    1. Use the cgwin building tool. setup the path for NDK jar file. Then u can build.

    2. @ DHarshana and Nauman Thanks.successfully i completed NDK buid using windows itself. Its working. But character recognition using this OCR is giving 50 % output only. wat i have to do for improve this?

  183. Error Shows.

    import com.googlecode.tesseract.android.TessBaseAPI

    TessBaseAPI

    Please help me

  184. Thanks for this post.settin up everythin was very straightforward for me.i have a runnin project but the text is sort of garbage.I just want to read 12digits serial numbers.is there a way to train mine to just 0-9.nunerals only and specified font?.thanks

  185. do anyone have idea of image processing for optimized results? if so please help me in that.

  186. Successfully i completed NDK buid using windows itself. Its working. But character recognition using this OCR is giving 50 % output only. wat i have to do for improve this?

    1. Here is the same problem! Although everything is ok, result is not perfect.
      How can I repair that?

  187. I have successfully builed the NDK in windows, using cmd. no issues at all/ set NDK and SDK paths correctly. no issues with that too. after i build NDK and trying to execute

    android update project –path .

    gives an error – ‘the project either have no target set or the target is invalid ‘

    somebody please help me with this. thank you !

    1. it did not work for the value ‘8’. but for the value ‘1’.

      the result is

      “updated project.properties
      added file \proguard-project.txt”

      is this the result i should be expecting ? thnx

    2. You can type “android list target” to see those available android targets on your machine. Then, specify the desired target_id to “android.bat update project -t target_id -p .”.

  188. When i Go to the eclipse and try to set the tess-two as the library. The library is now shown in there. i have checked the IsLibrary too. still nothing display as a library to select. please help me

  189. hi
    the library es perfecto , but the TextView in top left not show info in live camera , before capture image
    pleas help

  190. I am trying to develop the OCR to identify equations.
    I found a traineddata file that is ‘equ.traineddata’

    Can I use both ‘eng’ and ‘equ’ both tessdata to my app ?

    if so, how ??

    thnx

  191. Hi all
    I have imported Simple Android OCR application (complete project) , all work fine when tested on my phone but the output text doesn’t fit the text in the photo at all… why is this happening?

  192. Hi Gautam,

    I am trying to follow your tutorial (thanks by the way for this, there is not much documentation out there about tesseract). I encounter some issues at the end of the compilation:

    $ ndk-build
    Install : liblept.so => libs/armeabi/liblept.so
    Compile++ thumb : tess <= permdawg.cpp
    jni/com_googlecode_tesseract_android/src/dict/permdawg.cpp: In member function 'void tesseract::Dict::go_deeper_dawg_fxn(char const*, const BLOB_CHOICE_LIST_VECTOR&, int, const CHAR_FRAGMENT_INFO*, bool, WERD_CHOICE*, float*, float*, WERD_CHOICE*, int*, void*)':
    jni/com_googlecode_tesseract_android/src/dict/permdawg.cpp:208:62: error: format not a string literal and no format arguments [-Werror=format-security]
    cc1plus: some warnings being treated as errors

    make: *** [obj/local/armeabi/objs/tess/src/dict/permdawg.o] Error 1

    And I have lots of other warnings during compilation, such as:

    Compile++ thumb : lept <= readfile.cpp
    jni/com_googlecode_leptonica_android/readfile.cpp: In function 'jint Java_com_googlecode_leptonica_android_ReadFile_nativeReadFiles(JNIEnv*, jclass, jstring, jstring)':
    jni/com_googlecode_leptonica_android/readfile.cpp:103:12: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
    jni/com_googlecode_leptonica_android/readfile.cpp:109:12: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
    jni/com_googlecode_leptonica_android/readfile.cpp: In function 'jint Java_com_googlecode_leptonica_android_ReadFile_nativeReadFile(JNIEnv*, jclass, jstring)':
    jni/com_googlecode_leptonica_android/readfile.cpp:127:12: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]

    Any idea of how to solve this? I have a fresh download and install of ADT with NDK from less than a week and working on a MacBook.

    Config:

    $ uname -a
    Darwin MacBook-XXX.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

    $ ndk-build -v
    GNU Make 3.81
    Copyright (C) 2006 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.
    There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.

    This program built for x86_64-apple-darwin

    $ echo $PATH
    /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/christophe/Documents/ADT/ndk:/Users/christophe/Documents/ADT/sdk/tools/:/Users/christophe/Documents/ADT/sdk/platform-tools/

    1. There is an error on tess-two project, at line 208, file permdawg.cpp :
      jni/com_googlecode_tesseract_android/src/dict/permdawg.cpp:208:62: error: format not a string literal and no format

    2. Are we supposed to correct such errors? I have not seen anything about this case on the forums. Isn’t it more related to the compiler or system settings?

    3. Thanks for pointing this out. This problem was introduced with NDK v9. I committed a fix, so please pull the latest tess-two code and try the build again.

  193. I had completed all the step mentioned here to get the out put ..
    but unfortunately an exception occurred after taking the photo…
    so i made little bit change in my application and tested with a picture that manually pushed by me to the sdcard, when i running in emulator shows the following exception


    E/AndroidRuntime(3275): java.lang.ExceptionInInitializerError
    08- at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:212)
    08- at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.startCameraActivity(SimpleAndroidOCRActivity.java:122)
    08- at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity$ButtonClickHandler.onClick(SimpleAndroidOCRActivity.java:112)
    08- at android.view.View.performClick(View.java:4204)
    ...
    08- at java.lang.System.loadLibrary(System.java:535)
    08 at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:45)

  194. Gautam, I followed all the steps in your tutorial, and everything went according to plan. I successfully imported the tess-two library in eclipse, made it a library project and imported it into my project. But, at runtime, when I try to execute:

    baseApi.init(path, lang);

    I get an exception: ljava/lang/unsatisfiedlinkerror thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI

    can you please help me overcome this issue…
    I’m developing a simple OCR receipt scanner, and I’m working on windows8.

  195. Dear Gautam/rmtheis,

    I successfully integrated your advanced OCR. I need this app to identify few certain symbols that are used in mathematics such as pi and sigma. I have successfully followed the instruction of how to train a language in google groups.
    The problem I have is even I trained those symbols, they won’t appear in the OCR as it is. for an example if I scan the pi symbol, the OCR do not display the symbols as it is but it shows the corresponding letter of the keyboard which I used in the font.

    what would cause this problem ?

    thank you !

  196. I have imported Simple Android OCR application (complete project) , all work fine when tested on my phone but the output text doesn’t fit the text in the photo at all… why is this happening?

  197. I tried your basic as well as intermediate apps you have shared. The basic one doesn’t give accurate results but the intermediate one was giving a better output. Camera focus is having some problems some times in your intermediate app.

    But my question is that i am trying to build an Image to Text Converter using a Cloud(Server). Would you help me with it as i have no idea about cloud computing and the 2nd problem i am facing is that there are going to be diagrams too in the document the app will be converting. How to get the diagram out of it.

  198. Hi gautam,
    This is really a nice tutorial for beginners. Can you tell me what can i do for multiple words or text-lines. When i use huge amount words of image, the program-me crashes immediately.

    Thanks.

  199. Hi, how I can detect orientation of text to auto adjust image before OCR I wrote the next line baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD); and put the osd.trainddata file in the tessdata folder but it didn’t work. Please respond as soon as you can?

  200. Hi there,

    if I try to do TessBaseApi api = new TessBaseApi(); my application crashes.

    Does anyone know why?

    Thank you in advance.

    Greetings

    1. You can clean project to rebuild it, that will prevent exception like “couldn’t load lept from loader dalvik”.

  201. I seem to have a problem running my application. In particular, loading the libraries. I get the following error:
    E/AndroidRuntime(11472): Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load lept: findLibrary returned null

    I have tried cleaning the project and had no results.

    Any ideas?

  202. Hey Gautam. Thank you so much for this tutorial. I’m a newbie in android and this tutorial is really what I’m looking for. I have a challenge with building the tess-two project. I can’t seem to get the commands to work. I keep getting the error ‘no target set’ on cmd. I’m not sure whether I should write them one at a time or all of them together and whether to use cygwin or cmd on Windows vista. Please anyone help point me in the right direction.

    1. I think, You have to give Android target Version no. ( i.e. Android Max version).

  203. Hey Gautam. I tried to install but ran into difficulties. I’m using Windows and would appreciate some help:

    -Downloaded and extracted NDK
    -Downloaded tess-two as a ZIP file from Github, extracted it.
    -Using CMD I navigated to the tess-two folder, and ran ndk-build from inside the folder. It executed the script, which took about 15 minutes.

    This is now where I’m at. Tried to follow the next step, which is “android update project –path” CMD tells me “android” is not a recognized command. I thought it might be Windows, so I got cygwin and tried the same thing – it tells me “-bash: android: command not found”

    Next I tried to use Eclipse to build tess-two. I set NDK path as the NDK builder. Then I tried to import the tess-two project, but immediately I got the following errors: “Project has no project.properties file! Edit the project properties to set one.”

    I decided to plough on. I tried to set a new Builder for tess-two using NDK (I set the location as the path for ndk-build and set the working directory as $(workspace)/tess-two.

    However upon trying to build tess-two, it gave me the following build error:
    “Unable to resolve target ‘android-8′”. It then refuses to build.

    Where am I going wrong?

    1. Your “android” command was not found because you need to add the Android SDK to your PATH.

  204. Hi Gautam. I followed all the steps successfully. Everything works fine but I am not getting the exact text as the image contains. Please help me in this issue. Every time it returns something new or unique character. Thanks in advance.

  205. Hey Gautam, I cannot translate TRADITIONAL_CHINESE, zh_TW, to SIMPLIFIED_CHINESE, zh_CN. The TRADITIONAL_CHINESE can be scanned and show in screen but the output is remain in TRADITIONAL_CHINESE. The translation problem only occurs in zh_TW to zh_CN.

  206. Guys I need help, I don’t know how to build it, there was no ndk-build.cmd inside the tess-two folder

    1. After installing the NDK, you can go in your tess folder until ../tess-two as specified by Gautam.

      With command line put: “ndk-build Path-of-NDK-location” while working for windows command line. After building, go with command line in your SDK folder. (You will see some androids tools.). Type: “android update project -t 1 -p path-of-Tess-project”

      Finally there is the step with ant release but for now it failed for me.

    2. Hi back…correction being in your folder of tess 2 : put : /ndk-build, same thing for ant release : /ant release. Hope it will help. It is all right on Wndows command line in this way.

    1. Downlaod ant, extract the zip and set system variables to ant/bin folder. Close your command prompt and open it again, type ant -version

  207. Nice blog. Any ideas for getting better results using Tesseract? Please suggest any ideas on pre-processing the image before providing it to Tesseract for recognition..

    1. Hi, I was away for a bit. I manged to solve my problem. Simply used eclipse and set it as library then it produced a jar file with accompanying classes

  208. Hello, I am working on a Sencha Touch 2 + Phonegap 3 app and intend to use tess-two as an ocr plugin in phonegap. I have successfully build tess-two. However, the folder is about 400MB++ (way too big), which folder specifically should I copy for my project. Should it be the bin or libs or jni? Any feedback will be greatly appreciated

  209. Guys, I need help. I can finish step 1 to 3. But I’ve problem that I can’t understand it in step 4 and 5.
    the script in step 4 and 5, where it should be placed? Can anyone explain it, or give the whole script because I’ve stuck in that part.
    Thank you in advance.
    Best Regard.

  210. I don’t know why but I included the tess-two library and somehow tried to build it but failed (it seems to be built though). And then first I ran it on an emulator, it says SD card was corrupted/unavailable. After I solved the SD card problem, it just popped out a black screen and said OCR Test has stopped. Please help me

  211. I have done all your steps but couldn’t get the right result can you please tell me what is the problem.

  212. The app works fine with English traineddata(eng.traineddata). But i have to use it for French. i put the fra.traineddata file in assets/tessdata folder but it wont work. the error it shows:

    Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
    though there is sufficient storage on my phone.

    Please help.

  213. Hi Gautam, i moved on all steps and it build success fully but i get these error pls help me

    ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.rexdroid/.RexDroidOCRActivity }

  214. This is the error i getting pls help me to solve it……

    [2014-03-19 11:44:17 – Simple-Android-OCR] Installing Simple-Android-OCR.apk…
    [2014-03-19 11:44:37 – Simple-Android-OCR] Success!
    [2014-03-19 11:44:37 – tess-two] Could not find tess-two.apk!
    [2014-03-19 11:44:37 – Simple-Android-OCR] Starting activity com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity on device emulator-5554
    [2014-03-19 11:44:38 – Simple-Android-OCR] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.datumdroid.android.ocr.simple/.SimpleAndroidOCRActivity }

  215. After installing all s/w I am facing problem in step 2.
    ‘ndk-build’ is not recognize as an internal or external command, operable program or batch file.

  216. I have successfully completed all the steps as mentioned above.but,now i am getting error given below:
    tess-two] Failed to create BuildConfig class
    Simple-Android-OCR] Failed to create BuildConfig class
    tess-two] Failed to create BuildConfig class
    Simple-Android-OCR] Failed to create BuildConfig class
    Please Help me.

  217. Hello Gautam,

    Great job.

    I have a question for you. Do you think this OCR reader could be used in Google Glass? I want to implement an app using OCR reader for Google glass. Any thoughts?

    Thanks,
    Pramod

  218. Hello,
    I really enjoyed your tutorial, I used Tesseract in a school project and it worked well !
    I did a french translation of the installation on my blog, if you want to add to translation list 😉
    Thanks

  219. 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..

    1. 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: com.datumdroid.android.ocr.simple, 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/com.datumdroid.android.ocr.simple-1.apk”],nativeLibraryDirectories=[/data/app-lib/com.datumdroid.android.ocr.simple-1, /vendor/lib, /system/lib]]]: findLibrary returned null

  220. 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…
    Thanks!

  221. 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.

  222. 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..

  223. 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

  224. Hello, at the beginning :
    cd /tess-two
    ndk-build
    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.

  225. 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.

  226. java.lang.UnsatisfiedLinkError: Couldn’t load lept from loader
    dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/edu.sfsu.cs.orange.ocr-1.apk”], nativeLibraryDirectories=[/data/app-lib/edu.sfsu.cs.orange.ocr-1, /vendor/lib, /system/lib]]]: findLibrary returned null

  227. Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load lept from loader dalvik.system.PathClassLoader[dexPath=/data/app/edu.sfsu.cs.orange.ocr-1.apk,libraryPath=/data/app-lib/edu.sfsu.cs.orange.ocr-1]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)

  228. Hi Mr. Gautam,

    I followed your Instructions
    First I imported Tess-Two from github: https://github.com/rmtheis/tess-two
    And linked it to my project https://github.com/GautamGupta/Simple-Android-OCR
    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.setDebug(true);
    baseApi.init(DATA_PATH, lang);
    baseApi.setImage(bitmap);

    String recognizedText = baseApi.getUTF8Text();

    baseApi.end();

  229. 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 🙂

    1. @Mohamed

      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.

  230. nice job , but i have a problem
    i get this exception whenever it comes to initializing tesseract
    “Data path must contain subfolder tessdata ”
    but i’m sure the path is correct and the .trained file is there
    i’m familiar with tesseract – Emgu Cv C# – and things were so much easier
    i’m new to Android So your help will be appreciated

    1. Hi, i also have same problem like you now. Have you find out? Can you tell me how to solve it? Thanks 🙂

  231. Hello thanks for the tutorial, recently i started making an ocr app and its complete but i have a problem the text recognized are not accurate can you please give me a solution to this.
    Thanks for your time..

    George

  232. Im working on windows 7 PC. when I run ‘ant release’ on command prompt it returns

    C:\eclipseworkspace\tess-two-master\tess-two>ant realease
    Buildfile: C:\eclipseworkspace\tess-two-master\tess-two\build.xml

    BUILD FAILED
    Target “realease” does not exist in the project “tess-two”.

    Total time: 2 seconds

  233. i am trying to use the native lib in my Android project…
    Give an idea regrading OpenCV native library to use in my face recognition project and your project Optical character recognition ideas in my another app… Please give me some initial steps so that i’ll be able work out with my project..

    kindly reply

  234. Hi Mr.Gautam
    I have some problem in step 5. I’m trying to create rotation when I compile it has not a problem but the picture can not rotate. Please give me and idea. Thank you.

  235. Hello 🙂
    I can not execute this
    “About updating PATH – You need to update your PATH variable for the commands to function, otherwise you would see a command not found error. For Android SDK, add the location of the SDK’s tools and platform-tools directories to your PATH environment variable. For Android NDK, use the same process to add the android-ndk directory to the PATH variable.”
    Please help me

  236. Hello!
    I’ve followed your steps and eventually I build the tess-two project successfully (on windows 8.1 btw ), but when I try to run the app it doesn’t work. It says: “Could not find Simple-Android-OCR.apk!” Any suggestions?
    Thanks!

  237. Hello your post is really awesome i have successfully completed all the steps and no error in eclipse but when i run application i suddenly shows an error message that simple android OCR unfortunately stopped now what to do any suggestions please reply me as faster as possible…

  238. My application is running on mobile phone but it is not recognizing text properly…!!
    Any suggestions what to do for it…???

  239. HI Im just a starter in developing an android app. Is this efffective in Android Studio ? Ty

    1. Android Studio doesn’t have real NDK support, so personally I would give it a go in Eclipse.

  240. I am trying to include the tesseract OCR for a school project, but am getting Problems with the NDK. I am using NDK r10d on a mac mostly because I can not find r7c. So my Question is, what is the latest NDK compatible for this OCR?
    Here is my Error maybe that would help.
    Error:Execution failed for task ‘:tesstwo:compileReleaseNdk’.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Developer/adt-bundle-mac-x86_64-20140702/android-ndk-r10d/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/Android.mk APP_PLATFORM=android-8 NDK_OUT=/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/obj NDK_LIBS_OUT=/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/lib APP_ABI=all
    Error Code:
    2
    Output:
    In file included from /Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/src/main/jni/com_googlecode_leptonica_android/box.cpp:17:0:
    /Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/src/main/jni/com_googlecode_leptonica_android/common.h:22:24: fatal error: allheaders.h: No such file or directory
    #include
    ^
    compilation terminated.
    make: *** [/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/obj/local/arm64-v8a/objs/tesstwo//Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/src/main/jni/com_googlecode_leptonica_android/box.o] Error 1
    the path to the NDK should be correct…

    Thanks for your help,
    Adrian

    1. So it’s me again, it seems like a file (allheaders.h) is missing, thats why I thought, that the NDK r10d 64 bit might not workout. Others had problems using a other NDK as suggested. The oldest NDK I can download is the 10c, by changing download link manually as suggested in various Blogs.
      I am developing on Android Studio, as seen in the error.
      So far the Blog was great

      Thanks again,
      Adrian

    2. It’s not a problem with NDK r10d — I can build with that version of the NDK and all tests pass. You’re seeing a problem with importing the library project into Android Studio.

    3. So again it is me. I have now used NDK r7c and got a new Error. In the comments above were similar problems but under windows, and the answer seemed to be use Ubuntu.
      So despite I may be starting to seem like a spammer, I would like to here your advice to this error:
      Error:Execution failed for task ‘:tesstwo:compileReleaseNdk’.
      > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
      /Developer/android-ndk-r7c/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/Android.mk APP_PLATFORM=android-8 NDK_OUT=/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/obj NDK_LIBS_OUT=/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/lib APP_ABI=all
      Error Code:
      2
      Output:
      make: *** No rule to make target `/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release//Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/src/main/jni/com_googlecode_leptonica_android/box.cpp’, needed by `/Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/build/intermediates/ndk/release/obj/local/armeabi/objs/tesstwo//Users/myName/AndroidStudioProjects/TextErkennung2/tesstwo/src/main/jni/com_googlecode_leptonica_android/box.o’. Stop.

      Hope to here an Answer soon (is a school project and deadline is coming close – maybe I underestimated this)
      regards,
      Adrian

    4. hello sir adrian, i am a beginner and i just wanna know if it is fit in windows? and where should i build it ? in cmd ? thanks in advanced.

    5. @Jay
      As said I am using Mac OS X and Android Studio to develop. But Android Studio seems to have difficulty with the Library (as Robert Theis said). Eclipse is used in this tutorial so I can only recommend it, although I am having trouble with Eclipse and Android.
      Building my project with Tess-Two hasn’t worked yet so I am concentrating on other parts right now.
      As said I am not using Windows you might check other comments here, how they approached it. Or if that doesn’t help out check other tuts that are linked on this site.
      Regards,
      Adrian

  241. hi i looking to make a project using ocr which recognizes equations and solves them. I have never used ocr. i would like to to know if i can do this and if yes how so?

  242. Hello, im a student from cuba and i want to use tesseract library to develop an app that use the camera to recover data from a picture number and text and i dont have much internet acces i need help with that. Im using eclipse for the coding. I need to know how to use tesseract. Thanks

  243. I got following error can anyone help me?

    02-04 12:25:23.954: E/AndroidRuntime(10024): FATAL EXCEPTION: main
    02-04 12:25:23.954: E/AndroidRuntime(10024): java.lang.UnsatisfiedLinkError: Couldn't load lept from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/edu.sfsu.cs.orange.ocr-2.apk"],nativeLibraryDirectories=[/data/app-lib/edu.sfsu.cs.orange.ocr-2, /vendor/lib, /system/lib]]]: findLibrary returned null
    02-04 12:25:23.954: E/AndroidRuntime(10024): at java.lang.Runtime.loadLibrary(Runtime.java:355)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at java.lang.System.loadLibrary(System.java:525)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:43)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at edu.sfsu.cs.orange.ocr.CaptureActivity.initOcrEngine(CaptureActivity.java:711)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at edu.sfsu.cs.orange.ocr.CaptureActivity.onResume(CaptureActivity.java:368)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at com.lbe.security.service.core.client.b.x.callActivityOnResume(Unknown Source)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at android.app.Activity.performResume(Activity.java:5213)
    02-04 12:25:23.954: E/AndroidRuntime(10024): at miui.dexspy.DexspyInstaller.invokeOriginalMethodNative(Native Method)
    ...

  244. I want to add user word list for get more accuracy in tess-two or my project …….but i dont know how , plz help me

  245. @Sunil, give me your email address I will send you the solution, this error is occurred due to the project setup problem.

  246. Does anyone know how to implement the “torch_button” feature? I see it commented out but I’m not sure how to write the function to turn it on without the app crashing.

  247. I am using this demo but give me some time Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 4197 . I am not getting solution of this error. can you explain why i am getting this error.

  248. hey……hie gautam.. i followed the tutorial and it helped me a lot…but….it runs correctly at the first attempt…After my first attempt i have to re-install tha apk file and run again…otherwise it prints the garbage value..
    .can you provide any solution to this….?

  249. Hi,
    That was really awesome!
    I’m trying with something like this. Can you tell me how to get the baseline or Rect from the Tesseract?
    platform – android“`

  250. Hi. After giving up a bunch of times, I am finally able to run both the apps. I can understand the Simple Android OCR source, but is there a guide to the intermediate+ level Android OCR app?
    Thanks.

  251. 03-30 15:09:53.358 31833-31833/com.example.dellpc.material2 I/Tesseract(native)﹕ Attempting Init() with dir=/storage/emulated/0/BTP/, lang=dut11
    03-30 15:09:53.359 31833-31833/com.example.dellpc.material2 A/libc﹕ Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 31833 (ellpc.material2)

    i am getting this error and stopping my app when i try to native tessbaseapi init function

  252. Hi,
    That’s a very nice work. Am working on a school project. Android app which will read numbers on any surface via camera and give an option to either call or send sms to the scanned number.
    Am counting on you guys.
    Pls I need help on this.
    ASAP.
    Regards.

  253. when I import android-ocr-master Or simple-android-ocr-master in “Android Studio” make this error
    * Project OCRTest:E:\1-Our Project\android-ocr-master\android\project.properties:
    Library reference ..\..\tess\tess-two could not be found
    how i can fix it ?

  254. Hi, I wonder what kind of images OCR works, what are the allowed extensions or if a the results are better

  255. Hi Gautam
    Thanks for this article.

    Please is it possible to use Tesseract with Xamarin?

    I have been developing with Xamarin but I now need to build mobile applications with OCR capability.

  256. Hi guys, I need a help~ I stucked in the step 2 .
    I dont know how it actually working.

    cd /tess-two
    ndk-build
    android update project –path .
    ant release

    Can you guys tell me in details for each command line ?Please =(

  257. I am working on an app that requires OCR capabilities but facing difficulties with running the app,

    04-15 13:02:34.612: E/AndroidRuntime(7410): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/googlecode/tesseract/android/TessBaseAPI;

    searched the web since 4 hours, did not find a appropriate solution, can any one help me with this

    thanks

    1. did you properly build Tess-Two and imported..?
      and don’t forget to give reference of Tess-two to your project.

  258. hi thank you so much for this tutorial , you literally saved me !!! but i have one problem ! i tried to extract only the code that contains the selectable region while capturing from the intermediate+ project but i couldn’t .. any help please ! i don’t need full answer , just guide me to the right path :p

  259. For ANDROID STUDIO developers, here’s what I did on my Windows 8.1 machine.

    1) Download and install the ndk from here https://developer.android.com/tools/sdk/ndk/index.html. I had some trouble with its path in following steps so i put it in “C:\”.

    2) Add that path to environment variables of the system (eg: “C:\android_ndk_r10d”) and then reboot so your machine can find it.

    3) Download “tess-two-master” from here https://github.com/rmtheis/tess-two, extract it (for example in “C:\”) and rename it in “tess”.

    4) Open “tess” folder and then open “tess-two” folder. Click on a blank space while pressing the shift button and select “Open command window here”.

    5) Write “ndk-build” and wait until it completes (about 20min).

    6) Go back in the parent folder, select “eyes-two” folder and again click on a blank space while pressing the shift button in order to open the command window.

    7) Write “ndk-build” and wait.

    8) Write “android update project –target 1 –path C:\tess\tess-two”. Of course I assume your “tess” folder is located in “C:\”

    9) Write “ant release”. IF IT COMPLAINS go where you change your system environment variables as you did in step 2 and ADD a new variable with name “JAVA_HOME” and value the path to your jdk (eg: “C:\Program Files\Java\jdk1.8.0_40”)

    10) Open a completely new Android Studio project and follow these instructions https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle from section “Configure tess-two with gradle” but for safety don’t delete any folder or file even if he suggests to do so.
    I had some trouble with “build.gradle” file in “libraries\tess-two” directory, but it is sufficient to change some value on it. In my case I have:

    “classpath ‘com.android.tools.build:gradle:0.14.0′” instead of “classpath ‘com.android.tools.build:gradle:0.9.+’ ”

    and

    ” compileSdkVersion 21
    buildToolsVersion “21.0.2”
    defaultConfig {
    minSdkVersion 15
    targetSdkVersion 21
    } ”

    instead of

    ” compileSdkVersion 19
    buildToolsVersion “19.0.3”

    defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19}”.

    Note that the last step means you have to go in “File -> Project Structure -> Select a module from the left subwindow -> Dependencies (last tab) ->Press the green “+” on your right -> Module Dependency -> OK”

    11) Download this project https://github.com/GautamGupta/Simple-Android-OCR and copy&paste in your new project the code in these files: “SimpleAndroidOCRActivity.java”, “main.xml”, “strings.xml”. Of course your files may have different names (in my case “MainActivity.java”, “activity_main.xml”, “strings.xml”) so some renaming in the code may be necessary.
    Also open your “AndroidManifest.xml” and add at the end (but before “/manifest”) what you find between “/application” and “/manifest” in the just downloaded “AndroidManifest.xml” (it means that you have to add “uses-permissions” and “uses-feature” tag).

    12) Download from here https://code.google.com/p/tesseract-ocr/downloads/list the file in the language you prefer (eg: tesseract-ocr-3.02.eng.tar.gz ), extract it and locate the file “yourLanguage.traineddata” (eg: “eng.traineddata”). Forget for a moment your Android Studio IDE, open the folder of your project and go in “app–>src–>main”. Create here a new folder and name it “assets”. Open it and create another folder named “tessdata”. Put there your .traineddata file.

    13) Hope it was helpful, I obtained this after weeks of googling during free time, sometimes reaching page #10+. If I forgot something please forgive me and please reply this post without hesitation. Since I started android programming only 2 months ago I won’t be able to answer your questions. Forgive my bad english too.
    Ciao belli!

    1. Thanks a lot Matz.

      So if I put the .traineddata file in main/assets/tessdata, what should be the code here? :

      baseApi.init(DATA_PATH, lang);
      // Eg. baseApi.init(“/mnt/sdcard/tesseract/tessdata/eng.traineddata”, “eng”);

      thanks in advance,
      Quentin

    2. Thanks Matz. worked. Can I integrate a more refined character reader? This one is a bit confused. Or let me ask, how can I refine the library to read particular text? like certain text on a notice. Like particular fonts or patterns

    3. Hi, thanks for your tutorial.
      I got an error at step 5: “host awk tool is outdated. please define NDK_HOST_AWK to point to Gawk or Nawk!” I’ve tried to delete the outdated awk.exe file as instructed by others but no progress. Have you met such problems?

    4. Also if Someone could tell me what all to replace in the 11th step. that would be awsome!

    5. could you please explain the 8 step ” android update project –target 1 –path C:\tess\tess-two”??? because iv got error in cmd

    6. Hi! Im following all steps, but I get this gradle error…:

      Error:Configuration with name ‘default’ not found.

      Any thoughts?

    7. How can I do this step? 8) Write “android update project –target 1 –path C:\tess\tess-two”. Of course I assume your “tess” folder is located in “C:\”
      it gives me an error saying android is not recognized as an internal or external command. I put the sdk/tools and platform tools directory on the path environment variables but still it has that error. hope someone can help me. thank you

    8. Hello. Please, clarify something to me, do I need to have cygwin installed or something? when I run the ndk-build from the console I get the following:
      ”’ndk-build’ is not recognized as an internal or external command,
      operable program or batch file.

      D:\Development\workspace\android-studio\tess-two-master\tess-two>

    9. Hi, I’m getting an error when I run the command “ant release”. I’ve added JAVA_HOME variable and set its value as the path to the installation of the JDK.

    10. whenever i use “android update project –target 1 –path C:\tess\tess-two” it always shows an error. i.e., android is not recognized as an internal or external.
      Please help me as soon as possible.

    11. I am getting an error while compiling “android update project –target 1 –path C:\tess\tess-two”.
      Error is “Flag ‘-target’ is not valid for ‘update project’.” What to do next?

    12. While running “ant release” command, i am getting an error. The error message is:

      Buildfile: C:\Users\Pial-PC\Desktop\tesseract\eyes-two\build.xml

      BUILD FAILED
      C:\Users\Pial-PC\Desktop\tesseract\eyes-two\build.xml:46: sdk.dir is missing. Make sure to generate local.properties using ‘android update project’ or to inject it through an env var

      Total time: 1 second

    13. I am getting this error while building ndk-build in eyes-two

      C:\Users\VAIO\ocr\tess>ndk-build
      Android NDK: Could not find application project directory !
      Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
      C:\android-ndk-r10e\build/core/build-local.mk:143: *** Android NDK: Aborting
      . Stop.

    14. Hi Martz, I have tried to follow the step you described above. But I believe from step 10 it is confusing as lot of people stucked in that portion. It will be very much helpful if you can explain a little more from step 10.

    15. Hi Matz,

      i was doing the same as the steps mentioned. But when i am doing ndk build in eyes two i am getting some error :

      Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk

      E:/android-ndk-r10e/build/core/add-application.mk:199: *** Android NDK: Aborting
      … . Stop.

      could you please let me know what is the issue.

      Thanks.

    16. Hello and thank you for sharing your experience,

      I successfully got the app running but after returning from camera (taken image confirmation) got this error:

      java.lang.UnsatisfiedLinkError: Couldn’t load jpgt from loader dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.example.myapplication-1.apk”],nativeLibraryDirectories=[/data/app-lib/com.example.myapplication-1, /vendor/lib, /system/lib]]]: findLibrary returned null

      How could I get rid of that?

      Thanks

  260. Hi,my Simple android ocr is working well..But i want to replace the english trained data file with my new trained data file.How can i do that?..Can someone help me please!!..Thanks in advance.

    1. just replace eng.traindata into your train-data folder with your language data file.

  261. Hello, I am getting UnsatisfiedLinkError in initializing the project.

    05-07 12:02:30.844: E/AndroidRuntime(4477): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “rand” referenced by “liblept.so”…

    Any help would b good.

    1. Hello, It was issue related to toolchain version of NDK. previously I was using 4.9 which was causing the error. I moved backwards to version 4.8 and the issue solved.

  262. Can you help me on this? I got this error msg:

    05-11 15:56:08.093: I/DEBUG(2233): Abort message: ‘sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception ‘java.lang.NoSuchFieldError’ thrown in void com.googlecode.tesseract.android.TessBaseAPI.nativeClassInit():-2′

  263. Hi Robert,

    I think I got the error message when calling this method: nativeClassInit();

    Regards,
    Djaja

    1. Hmm, I’m having trouble reproducing the error. What version of Android are you running on? And what version of the NDK did you build with?

  264. I am getting this error message when this method is called:
    TessBaseAPI baseApi = new TessBaseAPI();

  265. Hello Gautam,

    My OCR project build was successful.When i run it on my phone it capture the image & store in sdCard but finally popup saying “Unfortunately OCRapp has stopped working”.
    Note: i haven’t import language file anywhere. Do i have to import it.
    ( tell me how and which file to download for English )
    (where to save the language file )

    Please help me very interested in your tutorial.

    1. hello anushka please help me.. I compile this tess-two but when run android update project i can’t. It says android is not recognized as an internal or external. Please help me what to do. As soon as possible. Please

    2. @Diadem
      I think first you have check whether your andorid sdk path is correct if it is correct try following command to update your projects.
      android update project -p .
      be carefull you must enter a dot at the end of command.

  266. @Matz,

    I’m using Android studio,I followed your instructions here.But stuck setting Environmental variable for windows. Do i have to use Cygwin. Because I install ndk then in the 8th instruction commandline says “android is not recognized as external or internal command.

    Help me on this.

    1. i’m so late, but for the others who want a answers,

      “android update project” command come from the Android SDK, not from NDK, i had the same problem.
      Android SDK from Android Studio is in AppData directory.
      C:\Users\Me\AppData\Local\Android\sdk\tools\Android.bat

      My Android sdk in not in environment variable.

      C:\Users\Me\Downloads\tess\eyes-two>C:\Users\Me\AppData\Local\Android\sdk\tools\android update project –t 1 –p C:\Users\Me\Downloads\tess\tess_two
      or
      C:\Users\Me\Downloads\tess\eyes-two>C:\Users\Me\AppData\Local\Android\sdk\tools\android update project –-target 1 –-path C:\Users\Me\Downloads\tess\tess_two

  267. 06-23 05:46:25.192: D/dalvikvm(1420): Added shared lib libjavacore.so 0x0
    06-23 05:46:25.212: D/dalvikvm(1420): Trying to load lib libnativehelper.so 0x0
    06-23 05:46:25.212: D/dalvikvm(1420): Added shared lib libnativehelper.so 0x0
    06-23 05:46:25.212: D/dalvikvm(1420): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
    06-23 05:46:25.432: D/dalvikvm(1420): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
    06-23 05:46:25.962: E/memtrack(1420): Couldn’t load memtrack module (No such file or directory)
    06-23 05:46:25.962: E/android.os.Debug(1420): failed to load memtrack module: -2
    06-23 05:46:26.252: D/AndroidRuntime(1420): Calling main entry com.android.commands.pm.Pm
    06-23 05:46:26.322: W/ActivityManager(385): No content provider found for permission revoke: file:///data/local/tmp/OCRTest.apk
    06-23 05:46:26.342: E/Vold(51): Error creating imagefile (Read-only file system)
    06-23 05:46:26.342: E/Vold(51): ASEC image file creation failed (Read-only file system)
    06-23 05:46:26.342: W/Vold(51): Returning OperationFailed – no handler for errno 30
    06-23 05:46:26.352: E/PackageHelper(644): Failed to create secure container smdl2tmp1
    06-23 05:46:26.352: E/DefContainer(644): Failed to create container smdl2tmp1
    06-23 05:46:26.352: W/ActivityManager(385): No content provider found for permission revoke: file:///data/local/tmp/OCRTest.apk
    06-23 05:46:26.442: D/dalvikvm(385): GC_EXPLICIT freed 452K, 30% free 5735K/8136K, paused 6ms+7ms, total 89ms
    06-23 05:46:26.482: D/AndroidRuntime(1420): Shutting down VM
    06-23 05:46:26.482: D/dalvikvm(1420): Debugger has detached; object registry had 1 entries
    06-23 05:46:26.492: D/dalvikvm(1420): Compiler shutdown in progress – discarding request

  268. My code gives this error boss help me with it

    06-24 14:29:11.398: E/AndroidRuntime(32082): FATAL EXCEPTION: main
    06-24 14:29:11.398: E/AndroidRuntime(32082): Process: com.example.asd, PID: 32082
    06-24 14:29:11.398: E/AndroidRuntime(32082): java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.example.asd-2/base.apk”],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn’t find “liblept.so”
    06-24 14:29:11.398: E/AndroidRuntime(32082): at java.lang.Runtime.loadLibrary(Runtime.java:366)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at java.lang.System.loadLibrary(System.java:988)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at com.googlecode.tesseract.android.TessBaseAPI.(TessBaseAPI.java:43)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at com.example.asd.MainActivity.onCreate(MainActivity.java:24)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.Activity.performCreate(Activity.java:5990)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.ActivityThread.access$800(ActivityThread.java:151)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.os.Handler.dispatchMessage(Handler.java:102)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.os.Looper.loop(Looper.java:135)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at android.app.ActivityThread.main(ActivityThread.java:5254)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at java.lang.reflect.Method.invoke(Native Method)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at java.lang.reflect.Method.invoke(Method.java:372)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    06-24 14:29:11.398: E/AndroidRuntime(32082): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

  269. Hi. I’m trying to use it in Eclipse but nothing is recognized. In particular, I have some troubles with “import android.graphics.Color;” where “The import android cannot be resolved” can you help me?

  270. I am in a big trouble. Unable to add the jni, as i am completely new to JNI. plus the application crashes the moment i click on scan.

    Please help me Gautam.

  271. hi gautam,

    i was able to successfully run the app in genymotion, and was trying to play with OCR using the laptop webcam. it is throwing different characters.

  272. New to OCR want to read My ID card with this but its not giving me expected result. Please let me know how i can define Region of Inetrest like left|Right|Bottom|top etc or Coordinates ??????

  273. hi. i want to develop a project for analysing text from form which is user entered. So, i want to scan that form and convert that image into text using ocr concept. i want to do it in android app. i am new to android app development and i am using eclipse. So, can you tell the step by step process for creating ocr application clearly? because, i don’t know how to use api. So, can you help me?

  274. Hi, I followed the tutorial but adapted it for Android Studio. The app loaded ok then I took a photo of text and when I tap on the check mark the app crashed. The first error message I got was:

    … failed: dlopen failed: cannot locate symbol “png_set_longjmp_fn” referenced by “liblept.so”…

    There are some other errors but I think they may be related to the first one. Can anyone help me to solve his problem?

    Thanks if you can point me in the right direction.

    1. Priyank Verma, I was able to get your built in “app” to work. It’s probably going to take me a couple of days to figure out how to make it work with mine (I’m new to this). Just wanted to say thanks!

    2. Hi Priyanka,

      Can you please help me to integrate it in cordova project?

      Thanks in advance!

  275. I am getting this error while building the files java.lang.UnsatisfiedLinkError: Couldn’t load pngt: findLibrary returned null . Can anybody help ??

    1. Are you using the latest version of tess-two? Are you using a precompiled library, or did you do an ndk-build on the latest version yourself?

  276. Hi!,

    I have cloned the repository then the following:
    – added to path:
    *export PATH=$PATH:/mnt/sdb1/android-sdk-linux
    *export PATH=$PATH:/mnt/sdb1/android-sdk-linux/platform-tools
    *export PATH=$PATH:/mnt/sdb1/android-ndk-r10e
    ndk-build and I get the following error:
    Android NDK: ERROR:/mnt/sdb1/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/Android.mk:gnustl_static: LOCAL_SRC_FILES points to a missing file
    Android NDK: Check that /mnt/sdb1/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/thumb/libgnustl_static.a exists or that its path is correct
    /mnt/sdb1/android-ndk-r10e/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.

    Please advise what to do. I’m running FedoraCore 21.

  277. hi we are trying to recognise hindi language using the hin.trainedata available for tesseract but it is not recognizing anything but when we replace the hindi training data by english it recognizes everything . any suggestion what might be the cause thank you

  278. Even I tried this Tesseract OCR part in Android. I was facing a run time error stating :
    java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “png_set_longjmp_fn” referenced by “liblept.so”

    I tried many things to figure it out. But ultimately replacing the libpng folder ( source ) with the one in this repo ( https://github.com/julienr/libpng-android ) and building it again ( ndk-build ) helped me. The app now runs without any error. Thought of sharing this. 🙂

    1. Are you using the latest code? Would you please open up an issue on the tess-two project with some steps to reproduce the error?

    2. No I didn’t. I think in the latest commit the bug is fixed. Sorry, didn’t look into that.

  279. Gautam, I keep getting java.noclassdef found error wen I type ant release..am running windows 7

  280. I am trying to make a software which can extract the MICR from the check. I am taking the screenshot from the camera and try to read the routing number and check number at the bottom of the check. But not able to read it accurately. Anyone please suggest what to do.

  281. Hi Gautam,Thank you for sharing this tutorial.I want to get the focus for the camera to select a text in the image as you shown in the screenshot above..how can i achieve that.can you please suggest.

  282. When i try to compile the project i got this Error.
    C:\Users\Sol\AndroidStudioProjects\MOBCharge\tesstwo\src\main\jni\com_googlecode_leptonica_android\common.h:22:24: fatal error: allheaders.h: No such file or directory
    #include
    ^
    compilation terminated.
    make.exe: *** [C:\Users\Sol\AndroidStudioProjects\MOBCharge\tesstwo\build\intermediates\ndk\release\obj/local/arm64-v8a/objs/tesstwo/C_\Users\Sol\AndroidStudioProjects\MOBCharge\tesstwo\src\main\jni\com_googlecode_leptonica_android\box.o] Error 1
    Error:Execution failed for task ‘:tesstwo:compileReleaseNdk’.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\android-ndk-r10e\ndk-build.cmd” finished with non-zero exit value 2

  283. hi , in the application of test OCR it if I choose the Arabic ocr it should download the training data every time I open the app .
    it don’t make the same in the other languages .

  284. First its a great guide.
    I am trying to implement the same currently, and i have run into small problem. I want to execute this project, please help me out here.
    So my problem is like this:-
    I am using windows 7 pc, android studio.
    so am following the instructions as given here
    https://gaut.am/making-an-ocr-android-app-using-tesseract/#comment-184181
    When i try to implment pint no 8 (adding path), i get following error.

    C:\Users\mack\AndroidStudioProjects\tess-two-master\tess-two-master\tess-two>android update project -target 1 -path C:\Users\mack\AndroidStudioProjects\tess-two-master\tess-two-maste
    r\tess-two
    Error: Argument ‘C:\Users\mack\AndroidStudioProjects\tess-two-master\tess-two-master\tess-two’ is not recognized.

    Usage:
    android [global options] update project [action options]
    Global options:
    -s –silent : Silent mode, shows errors only.
    -v –verbose : Verbose mode, shows errors, warnings and all messages.
    –clear-cache: Clear the SDK Manager repository manifest cache.
    -h –help : Help on a specific command.

    Action “update project”:
    Updates an Android project (must already have an AndroidManifest.xml).
    Options:
    -s –subprojects: Also updates any projects in sub-folders, such as test
    projects.
    -l –library : Directory of an Android library to add, relative to this
    project’s directory.
    -p –path : The project’s directory. [required]
    -n –name : Project name.
    -t –target : Target ID to set for the project.

    Please help me out here, i tried to google the error but didnt find anything fruitful.

    1. I tried this :
      my sdk is not in environment variable.
      my ndk is not too.
      path of my eyes-two : C:\Users\Me\Downloads\tess\eyes-two
      command in eyes-two directory :

      C:\Users\Me\Downloads\tess\eyes-two>C:\Users\Me\AppData\Local\Android\sdk\tools\android update project –target 1 –path C:\Users\Me\Downloads\tess\tess_two

      And it works :

      Result displayed:
      C:\Users\Me\Downloads\tess\eyes-two>C:\Users\Me\AppData\Local\Android\sdk\tools\android update project -t 1 -p C:\Users\Me\Downloads\tess\tess-two
      updated project.properties
      updated local.properties
      Added file C:\Users\Me\Downloads\tess\tess-two\proguard-project.txt

    2. oups mistake, command in eyes-two directory:
      C:\Users\Me\Downloads\tess\eyes-two>C:\Users\Me\AppData\Local\Android\sdk\tools\android update project -–target 1 –-path C:\Users\Me\Downloads\tess\tess_two
      or
      C:\Users\Me\Downloads\tess\eyes-two>C:\Users\Me\AppData\Local\Android\sdk\tools\android update project –t 1 –p C:\Users\Me\Downloads\tess\tess_two

      action options synthax
      -p or –path
      -t or –target

  285. great tutorial. still works like a charm. our further intention is to further train the model to recognize handwriting better, any idea how that can be done?
    Thank you.

  286. 01-29 14:20:53.779: W/dalvikvm(25363): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI;
    01-29 14:20:53.779: D/AndroidRuntime(25363): Shutting down VM
    ...
    01-29 14:20:53.781: E/AndroidRuntime(25363): at dalvik.system.NativeStart.main(Native Method)

    it occurs “unfortunately stopped” error after capturing the image

  287. brother i made app successfully but its not giving the right result all the time kindly tell me how to improve accuracy

  288. I am using windows 8.1 pro with android studio 1.51 ,I am getting an error in step 9 ,it says that ant is not recognized as an internal or external command , can someone please help me out , thanks in advance

  289. I’m using a Nexus 6p for testing and every time I press the tick after I take a picture, it returns a 0 result code, meaning the onPhotoTaken method never get’s hit. Any ideas as to why it always returns 0?

  290. hello Follow all steps but
    i have problem in my app ,
    “unfortunately stopped” error after capturing the image and exit my app
    please help me

  291. Good job, we need people like you
    thanx.

    But my story is that i can’t be able to compile on my android device it could not be able to resolve the native function path.

  292. Hi guys, can i konw how photomath app is working… Am doing it as my final year project. Can any one help me in developing it

  293. hello friends imgetting step 7) Write “ndk-build” and wait.

    C:\Users\admin\Downloads\tess-two-master\eyes-two>ndk-build
    Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk

    C:/android-ndk-r11c/build//../build/core/add-application.mk:195: *** Android NDK
    : Aborting… . Stop.

    C:\Users\admin\Downloads\tess-two-master\eyes-two>

    Please help

    1. Hi,

      I fixed this problem with copy “tess/eyes-two/src/main/*” to “tess/eyes-two/*” (you need to override the “AndroidManifest” file.

      edit the “tess/eyes-two/jni/Android.mk” :

      line 2 for:
      TESSERACT_TOOLS_PATH := $(call my-dir)/../../tess-two

      (remove some ../../)

      and it should be good

  294. hello friends im getting error step 8) also

    C:\Users\admin\Downloads\tess-two-master\eyes-two>C:\Users\admin\AppData\Local\A
    ndroid\sdk\tools\android update project -t 1 -p C:\Users\admin\Downloads\tess-tw
    o-master\tess-two
    Error: Argument ‘C:\Users\admin\Downloads\tess-two-master\tess-two’ is not recog
    nized.

  295. Hi!. How can use this librari with Android Studio?.

    I ‘m trying to use the library , but do not know how is used.

  296. To everyone having trouble: Please take a look at the updated Usage instructions in the tess-two project Readme. The project is much easier to use now, and you no longer have to do the ndk-build step yourself!

  297. hello im umer …how can we do this if we have to read text from two different parts of a picture at the same time ? for example reading 1) meter no and 2) units from electricity meter

  298. I followed your step and I can build tess two in cmd with the command “ndk-build”. But I can’t write another command which is – ” android update project –target 1 –path C:\tess\tess-two “. However I did it only says – ” ‘android’ is not recognized as an internal or external command, operable program or batch file. ” Is there anything I have misunderstood about your post? Please tell me where did I go wrong.

  299. Why I can’t write ‘ant release’ . It always show ‘ant’ is recognize as an internal or external command,operable program or batch file.
    I add my system environment variables as I did in step 2 and ADD a new variable with name “JAVA_HOME” and value the path to my jdk but It always show that. Please help me

  300. I am using android studios IDE.Can you help me with this error “Could not initialize Tesseract API with language=eng!”.

  301. hello, i am working on a project on android application which extract receipt images text and save it using OCR API. The problem i am having is that i want some way so that image potion can be selectable to user so that it highlight amount and date on the receipt and it will be extracted in separate text box. I want this because i am having accuracy problem with java regex.kindly guide me any way so that user selects amount or date potions on the image either marking or highlighting it and ocr will extract that parts.

  302. I have doubt regarding security. Will my data be revealed to outside other than my app. I mean, will it stored or sent to some third party for processing. Can I make sure that my Image information or text inside that is not sent any third party without my control.

  303. Good morning everyone!
    Is it possible to have two areas for taking the picture?
    in short, to have two focusboxview ?
    thank you

  304. Does the data collected from the image need to be sent through to tesseract, or can it be built in such a way that the information isn’t sent away anywhere?

  305. in the pass 9, if it complains, execute the next command line for pass the project to target 8:

    android update project –subprojects –path . –target “android-8”

    It work for me

  306. Where should i type this step “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 /tess-two
    ndk-build
    android update project –path .
    ant release”

  307. Hey Gautam, i followed all the instructions here and it work, but the app doesn’t give an accurate result. All I’m getting is weird text that doesn’t belong to the image even if I binarized and remove noise on the image. . .

    Can u give us a suggestion? Please. . . . . 🙂

  308. I have got to the stage to type in ‘ant release’ but when i do, i get an error message saying, ” ‘ant’ is not recognised as an internal or external command” but I’ve added an environment variable JAVA_HOME with the correct directory of the jdk. What have i done wrong?

  309. Hello, did anyone find a solution for “the app has stopped working” problem ? when I click the button to start scanning, the app crashes in my Genymotion emulator. I have tried various devices and restarted both Genymotion and Android Studio multiple times just to make sure but I have the same issue.

  310. Please tell how may i download language file and where i have to keep it in my program…

  311. Hey Gautam Great Tutorial 🙂 I have cloned the downloaded the applications on github but when I run the application I get this error

    Error:Execution failed for task ‘:OCRTest:transformNative_libsWithStripDebugSymbolForDebug’.
    > java.lang.NullPointerException (no error message)

    Any ideas on what the issue is? feedback would be very appreciated 🙂

  312. Hi Gautam! I tried using the application. It is pretty good. One thing i have found is that when i focus the images from camera on an object and then it gives me an error like

    12-24 16:33:45.709: A/libc(16592): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 16592 (roid.ocr.simple)

    Also when i test the applications more than one two times adjusting the focus it gives me nothing the the recognized. The program stops after this

    12-24 16:33:45.184: I/Tesseract(native)(16592): Initialized Tesseract API with language=eng

    Please help!

  313. Hello. I scan Letter “A” and already display in OcrTextView but I need to use if else for my codes. Example.
    If (OCRResult == “A”){
    \\do something
    }
    The result is always false. Whats wrong?

  314. C:\tess\tess-two>ndk-build
    ‘ndk-build’ is not recognized as an internal or external command,
    operable program or batch file.

  315. Hello Gautam! I am getting error…Cannot initialize camera. Please help me in this.

  316. Hi,
    It is really nice work to I want to do the same thing on IOS using teserect and openCV to detect specific text.
    Could you please send me some links or an example app to guide?
    Thanks in advance.

  317. Hello Gautam,
    It is an interesting article. I am doing a project which requires to read Australian IDs and Arabic IDs and convert them to text in relevant fields. Could you please help me in developing an OCR software which will be embedded in to my software. Please note I need it work offline and don’t want to pay on going license fee. One off development cost is OK.
    Thanks.

  318. Hello, I want to Reject when an image is not clear for this what can I used please guess me some filters.

  319. Hello Gautam,
    Can we use this app for text extraction from devnagiri and other languages as well if use the other traindata file?

  320. we got this error.please reply as early as possible.
    ”’ndk-build’ is not recognized as an internal or external command,
    operable program or batch file.

    1. Just add ndk-path to your environment variables.
      In my case I edit the “path” variable name in mine and put this:
      “C:\Users\Valerie\AppData\Local\Android\sdk;” . Just make sure to put “;” at the end then restart your pc and try again running ndk-build command.

  321. Hi, I have followed all the steps correctly multiple times but I keep on getting the errors below while running the ant release command. Can someone please help me regarding this errors? Thank you/

    -compile:
    [javac] Compiling 24 source files to D:\tess\tess-two\bin\classes
    [javac] warning: [options] source value 1.5 is obsolete and will be removed
    in a future release
    [javac] warning: [options] target value 1.5 is obsolete and will be removed
    in a future release
    [javac] warning: [options] To suppress warnings about obsolete options, use
    -Xlint:-options.
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Pix.java:20: e
    rror: package android.support.annotation does not exist
    [javac] import android.support.annotation.ColorInt;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Pix.java:21: e
    rror: package android.support.annotation does not exist
    [javac] import android.support.annotation.Size;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Binarize.java:
    19: error: package android.support.annotation does not exist
    [javac] import android.support.annotation.FloatRange;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Box.java:20: e
    rror: package android.support.annotation does not exist
    [javac] import android.support.annotation.Size;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Boxa.java:20:
    error: package android.support.annotation does not exist
    [javac] import android.support.annotation.Size;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Constants.java
    :19: error: package android.support.annotation does not exist
    [javac] import android.support.annotation.IntDef;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Constants.java
    :56: error: cannot find symbol
    [javac] @IntDef({L_INSERT, L_COPY, L_CLONE})
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class Constants
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Constants.java
    :79: error: cannot find symbol
    [javac] @IntDef({L_SORT_INCREASING, L_SORT_DECREASING})
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class Constants
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Constants.java
    :89: error: cannot find symbol
    [javac] @IntDef({L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH, L_SORT_BY_HE
    IGHT, L_SORT_BY_MIN_DIMENSION,
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class Constants
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Edge.java:19:
    error: package android.support.annotation does not exist
    [javac] import android.support.annotation.IntDef;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Edge.java:38:
    error: cannot find symbol
    [javac] @IntDef({L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, L_ALL_EDGES})
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class Edge
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\JpegIO.java:21
    : error: package android.support.annotation does not exist
    [javac] import android.support.annotation.IntRange;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\MorphApp.java:
    19: error: package android.support.annotation does not exist
    [javac] import android.support.annotation.IntDef;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\MorphApp.java:
    38: error: cannot find symbol
    [javac] @IntDef({L_TOPHAT_BLACK, L_TOPHAT_WHITE})
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class MorphApp
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Pixa.java:20:
    error: package android.support.annotation does not exist
    [javac] import android.support.annotation.Size;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Rotate.java:19
    : error: package android.support.annotation does not exist
    [javac] import android.support.annotation.IntRange;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:22: error: package android.support.annotation does not exist
    [javac] import android.support.annotation.IntDef;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:23: error: package android.support.annotation does not exist
    [javac] import android.support.annotation.WorkerThread;
    [javac] ^
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:60: error: cannot find symbol
    [javac] @IntDef({PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO
    , PSM_SINGLE_COLUMN,
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class PageSegMode
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:124: error: cannot find symbol
    [javac] @IntDef({OEM_TESSERACT_ONLY, OEM_CUBE_ONLY, OEM_TESSERACT_CUBE_C
    OMBINED, OEM_DEFAULT})
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class TessBaseAPI
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:151: error: cannot find symbol
    [javac] @IntDef({RIL_BLOCK, RIL_PARA, RIL_TEXTLINE, RIL_WORD, RIL_SY
    MBOL})
    [javac] ^
    [javac] symbol: class IntDef
    [javac] location: class PageIteratorLevel
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Pix.java:130:
    error: cannot find symbol
    [javac] public boolean getDimensions(@Size(min=3) int[] dimensions) {
    [javac] ^
    [javac] symbol: class Size
    [javac] location: class Pix
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Pix.java:302:
    error: cannot find symbol
    [javac] public void setPixel(int x, int y, @ColorInt int color) {
    [javac] ^
    [javac] symbol: class ColorInt
    [javac] location: class Pix
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Binarize.java:
    124: error: cannot find symbol
    [javac] @FloatRange(from=0.0, to
    =1.0) float scoreFraction) {
    [javac] ^
    [javac] symbol: class FloatRange
    [javac] location: class Binarize
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Binarize.java:
    190: error: cannot find symbol
    [javac] public static Pix sauvolaBinarizeTiled(Pix pixs, int whsize, @Fl
    oatRange(from=0.0) float factor,
    [javac] ^
    [javac] symbol: class FloatRange
    [javac] location: class Binarize
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Box.java:190:
    error: cannot find symbol
    [javac] public boolean getGeometry(@Size(min=4) int[] geometry) {
    [javac] ^
    [javac] symbol: class Size
    [javac] location: class Box
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Boxa.java:121:
    error: cannot find symbol
    [javac] public boolean getGeometry(int index, @Size(min=4) int[] geometr
    y) {
    [javac] ^
    [javac] symbol: class Size
    [javac] location: class Boxa
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\JpegIO.java:64
    : error: cannot find symbol
    [javac] public static byte[] compressToJpeg(Pix pixs, @IntRange(from=0,
    to=100) int quality,
    [javac] ^
    [javac] symbol: class IntRange
    [javac] location: class JpegIO
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Pixa.java:359:
    error: cannot find symbol
    [javac] public boolean getBoxGeometry(int index, @Size(min=4) int[] dime
    nsions) {
    [javac] ^
    [javac] symbol: class Size
    [javac] location: class Pixa
    [javac] D:\tess\tess-two\src\com\googlecode\leptonica\android\Rotate.java:10
    6: error: cannot find symbol
    [javac] public static Pix rotateOrth(Pix pixs, @IntRange(from=0, to=3) i
    nt quads) {
    [javac] ^
    [javac] symbol: class IntRange
    [javac] location: class Rotate
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:508: error: cannot find symbol
    [javac] @WorkerThread
    [javac] ^
    ...
    [javac] @WorkerThread
    [javac] ^
    [javac] symbol: class WorkerThread
    [javac] location: class TessBaseAPI
    [javac] D:\tess\tess-two\src\com\googlecode\tesseract\android\TessBaseAPI.ja
    va:753: error: cannot find symbol
    [javac] @WorkerThread
    [javac] ^
    [javac] symbol: class WorkerThread
    [javac] location: class TessBaseAPI
    [javac] 36 errors
    [javac] 3 warnings

    BUILD FAILED
    C:\Users\Valerie\AppData\Local\Android\sdk\tools\ant\build.xml:716: The followin
    g error occurred while executing this line:
    C:\Users\Valerie\AppData\Local\Android\sdk\tools\ant\build.xml:730: Compile fail
    ed; see the compiler error output for details.

    Total time: 18 seconds

  322. Hi,
    I saw now it’s working just for English language. How to make it to work for all languages?

  323. I want to detect Marathi/Hindi language and get it translated in English. How to do the same?

  324. I am using tess two 9.0.0 to scan MRZ of passport. Its working fine but if used continuously the ‘ getHOCRText ‘ method become very slow to read the text. To improve the performance I am passing the binarised image but not getting any result. Can’t figure out the issue. Kindly help.

  325. Hi Gautam
    I am developing same app on iOS Please tell me what should be folder structure. I have done 1 for Camera and one for OCR is it correct? As I always get error of -h file missing.

  326. Hey nice article but I was searching a way to call this code from c++ on android is that possible

Comments are closed.