20

I have searched on the net for a couple of hours. I got many answers saying we need to use NDK, etc. for "Tesseract" for WINDOWS.

But I didn't get any step-by-step/proper explanation of what should be done when NDK is installed. How to get the .so files? I have finished installing NDK and Cygwin. To check if it's done properly, I entered make -v and it gave the expected output.

Can anyone who has used "Tesseract" tell me how they have done it? (I have downloaded "Mezzofanti", but there I didn't find any of the "Tesseract" files.)

rmtheis
  • 5,992
  • 12
  • 61
  • 78
PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53

4 Answers4

22

You need to use tess-two project for working with Tesseract on Android.
The tess-two contains tools for compiling the Tesseract and Leptonica libraries for use on the Android platform. It provides a Java API for accessing natively-compiled Tesseract and Leptonica APIs.

Adding tess-two to your project:

add to build.gradle:

dependencies {
    compile 'com.rmtheis:tess-two:5.4.1'
}

Using Tesseract:

import com.googlecode.tesseract.android.TessBaseAPI;

private String extractText(Bitmap bitmap) throws Exception{
    TessBaseAPI tessBaseApi = new TessBaseAPI();
    tessBaseApi.init(DATA_PATH, "eng");
    tessBaseApi.setImage(bitmap);
    String extractedText = tessBaseApi.getUTF8Text();
    tessBaseApi.end();
    return extractedText;
}

You can looking on my simple one-class example of using Tesseract for Android. It contains only 200 lines of Java code.

Morteza Jalambadani
  • 2,190
  • 6
  • 21
  • 35
Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
  • 1
    Nice! You should target api 22 instead because your app doesn't request [runtime permissions](https://developer.android.com/training/permissions/requesting.html) from the user. – rmtheis Aug 25 '16 at 05:22
  • Trying to clear just a bit of doubt. I think OCR are CPU intensive, don't you think performing OCR at the user hand held devices can cause their devices slow. I guess preforming the OCR at server level and then reverting back to the user with information would be great. What do you think ? – Lokesh Pandey Apr 22 '17 at 03:59
  • @Lokesh Yes, you are right. OCR takes time. It will work 3x faster on server. – Yuliia Ashomok Apr 22 '17 at 12:19
  • I followed you contribution on github. It's great ! . But I have few documents which contains multi language. And in that the application is unable to OCR that document. And also the application didn't come up with right OCR every time when I tested the same document again and again with perfect image but at different angle. Any suggestion for this ? – Lokesh Pandey Apr 22 '17 at 12:40
  • 2
    @Lokesh try to use Google Vision OCR instead of Tesseract. It is not free but cheap. It gives excellent results for multi language and any angle. – Yuliia Ashomok Apr 22 '17 at 16:37
  • @Lokesh multi language is possible for Tesseract but I have 0 experience with it and no time to help you with it. Sorry. – Yuliia Ashomok Apr 22 '17 at 16:39
  • Thank you, I guess now it's my time to contribute something :) . What I am trying to do is to merge the train data into a single file to OCR the document. – Lokesh Pandey Apr 23 '17 at 01:59
  • 2
    @Lokesh while the OCR is CPU and memory intensive task on local device, using server solution has its own disadvantages. You have to upload the picture data to the server (pictures take from tens-kilobytes to couple of megabytes data to upload, depending on the resolution and preprocessing = takes time to upload). And you have to make sure your solution is reasonably secure (for example if you are trying to scan people ID cards, you should spend serious budget on the security of the solution, as leakage of the photo would be very sensitive). In the end it may be safer+faster to OCR on device. – Ped7g May 09 '18 at 09:13
  • 2
    @Lokesh actually depends a lot on from where the picture data are sourced. If you are doing OCR over some data from Internet, then it will be probably faster to put request on your server service with desired url, let the server download image, run OCR and send text results to app.. if the source of image is device camera, then it may be problematic to upload raw data to server (taking too long + too much data), but with some heavy preprocessing you may get to upload only 50-200kB of picture data, which may be OK for some countries with good data services. – Ped7g May 09 '18 at 09:15
  • This was really useful but I advise to check for the latest version of the Tess-two library by visiting https://github.com/rmtheis/tess-two ✌ – Neil Palethorpe Nov 10 '18 at 12:50
  • Other parts are easy to follow but I need more information about that `DATA_PATH`. It seems I need to copy some data but that sample lacks explanation for that. – Damn Vegetables Nov 18 '19 at 15:42
  • The code caused `A/libc: Fatal signal 11 (SIGSEGV)`. I had to change the version to `'com.rmtheis:tess-two:9.1.0'` and run it in a real device, because Android emulator (x86) cased that error. Maybe the library only supports ARM. – Damn Vegetables Nov 18 '19 at 16:18
  • this repo no longer maintain – newbie Oct 31 '21 at 20:32
15

You can refer this document, It gives ths step by step But you need to do is to set up the tesseract-android-tools project as a library project in Eclipse, and tell your project to refer to the library project. So you’ll need two projects in Eclipse,

http://rmtheis.wordpress.com/2011/08/06/using-tesseract-tools-for-android-to-create-a-basic-ocr-app/

I hope this help.....

Uttam
  • 12,361
  • 3
  • 33
  • 30
  • I have made the changes in my question... I need it for WINDOWS XP OS. – PrincessLeiha Oct 10 '11 at 09:42
  • I went through the "READ ME" but it's giving an error "Cloning into libjpeg... android.git.kernel.org[0: 149.20.4.77]: errno=No route to host fatal: unable to connect a socket (No route to host)" after this step, "git clone git://android.git.kernel.org/platform/external/jpeg.git libjpeg" in readme – PrincessLeiha Oct 10 '11 at 09:56
  • Found problem: This is the alternative mirror "https://github.com/android/platform_external_jpeg" – PrincessLeiha Oct 10 '11 at 09:59
  • @Pallavi do use git clone git://github.com/android/platform_external_jpeg.git libjpeg – Hanry Oct 14 '11 at 13:22
  • @Pallavi you also check out this. http://code.google.com/p/tesseract-android-tools/issues/detail?id=5#c21 – Uttam Oct 19 '11 at 04:52
  • well, I followed the steps given... I build the file using "ndk-build" command in cygwin.. but it's not creating the 2nd .SO file. – PrincessLeiha Oct 19 '11 at 05:07
  • @Pallavi Sorry I can't help for that because i have configured tesseract in Ubuntu 11.04. That's work fine. – Uttam Oct 19 '11 at 05:13
1

http://kurup87.blogspot.in/2012/03/android-ocr-tutorial-image-to-text.html here is step by step tutorial

Mr_Hmp
  • 2,474
  • 2
  • 35
  • 53
-1

This video shows you exactly how it is done

How can I use Tesseract in Android?

Make sure to: 1. Create the folder 2. in that folder you have to put the traineddata file (You can download it from here in the language you require https://github.com/tesseract-ocr/tessdata/tree/3.04.00 ) 3. Reference the path to the folder cointining the traineddata file and state the language: tessBaseApi.init(DATA_PATH, "eng");

Hope it helps