How to build Tesseract OCR library for Android Studio?

Star On GitHub

If you ever tried to create an OCR app for Android you must have stumbled upon the OCR library by Google Tesseract. And then the problems began.

To use the library in your project you first need to build it. But building the library to be compatible with gradle, which is the new build system for Android projects is little not so easily stated anywhere in the library manual.

When I tried to build the library, it took me freaking 9 hours to figure all the how tos?

So, here I am helping you to save your precious hours. (Don’t waste these watching late night infomercials for god’s sake! ).

Here we go.

Step 1 : 

The first step. Download the NDK. That is used to build the library.

Download it from here. It is around 300+ MB so keep your net plan nourished.

Step 2 : 

Better way to go is to use  a fork of Tesseract, Tess-Two. Tess-Two can be found on GitHub.

Execute following commands to build the library Tess-Two using NDK.


git clone git://github.com/rmtheis/tess-two tess
cd tess
cd tess-two
ndk-build
android update project --path .
ant release

We can live without building eyes-two for this time.

Building will take few minutes. After you have successfully built tess-two, give yourself a little treat. You are almost done.

Step 3 :

Now you are ready to use the library in your Android project.

Copy the tess-two folder (tess/tess-two), in the main folder of the application project.

Suppose name of your application is “MyApp” copy the folder at “MyApp/”.

Step 4 :

Now its time to play the trick. The library was build using ANT. But Android projects use Gradle these days. Interesting…

We need to add a “build.gradle” file at location “tess-two/”.

The build file can be found here.

Then include following line in project.settings file.

include ':tess-two'

Step 5 : 

Build the project and you are just one step away from being done.

Step 6 : 

The most important step. After completing steps 1-5, throw your hands up in the air! 😀 😀 You are now done!

Ready to harness the power of OCR.

 


https://buttons.github.io/buttons.js

Advertisements

13 thoughts on “How to build Tesseract OCR library for Android Studio?

  1. Wow, this one the latest tutorial that I found .

    May I know, which OS, NDK that you use ..

    I had stuck one week on the ndk-build ..

    make.exe *** Waiting for unfinished job.

    I am very newbie .. But this project is very important .. 😥 .

    Thank you in advance ..

    Like

  2. I am getting this error. Please help me

    @Below Line
    baseApi.init(“/mnt/sdcard/tesseract/tessdata/eng.trainedata”, “eng”);

    Error : Caused by: java.lang.IllegalArgumentException: Data path does not exist!

    Like

  3. i got this error: Error: The project either has no target set or the target is invalid.
    when i’m trying to do: android update project –path .

    Like

  4. salam. i need a bit help actually, i got stuck on ur step 2 tutorial, i do really apreciate if u want to help me this tutorial just so important for my final project, i dont even know how to execute following commands to build the library Tess-Two using NDK, please help me get out of step 2, ur help means a lot. if u want to help me please contact this email : aghnia35@gmail.com . thankyou. salam.

    Like

  5. My friend;
    I have tried to follow all steps you have; however, I could not performed two steps below. I have searched my computer for “android.exe and ant.exe”; however, I have no luck. I have tried google for android.exe, but nothing there. I also update sdk platform tools and download apache ant, but nothing seem to work.

    Thanks

    android update project –path .
    ant release

    Like

  6. So the app doesn’t need internet connection to use? Can’t I make an online app using tesseract? I’m really confuse here, please help 😦

    Like

    1. To doesn’t need internet as everything is happening on device.
      You can make online app but then you’ll have to send image to your server which analyses the image.

      Like

  7. Hello priyank! I have followed all 6 steps successfully. I run project also. But I am not getting how to use ocr library. Please help. It’s running activity in my project. Nothing in ocr is happening. Guide please.

    Like

  8. Hello priyank! I have followed all 6 steps successfully. I ran project also. But I am not getting how to use ocr library. Please help. It’s running activity in my project. Nothing in ocr is happening. Guide please.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s