Use of tesseract for Android text recognition

Source: Internet
Author: User

About the Tesseract identification tool there is a version of Google provides tesseract-android-tools, but there is also a tesseract-two is very useful, here we use Tesseract-two. Tesseract is implemented in C + + and requires encapsulation of Java APIs for Android platform calls. So before using Tesseract-two, download the android-ndk, download the NDK, unzip it to a folder on your computer, and configure the NDK referenced by Eclipse.

Unzip the downloaded NDK, because to use ndk-build this command and for the sake of convenience, without CD to CD to the ~ Configure the environment variables, in path to append the NDK extracted directory.

Tesseract-two is actually a git branch of tesseract tools for Android, which is chosen because it is simple to operate and integrates with Leptonica, a graphical processing tool. So you can download it on the Gitbub.

Https://github.com/rmtheis/tess-two

You can also use Git to get the resources you want.

Http://git-scm.com/download/win

The resources are ready, and then we compile with the NDK (Cmd entered under Windows) and enter the following command (compile time will be a bit longer)

CD tess-two  ndk-build  android update Project-t 1--path.  Ant release      cd  . CD eyes-two  ndk-build  android update Project-t 1--path.  Ant Release  

The Android project in Eclipse imports the compiled library, a total of three items, Tess-two,tess-two-test and Eyes-two. Among them, Tess-two and Eyes-two are Android Lib projects that are referenced by other projects.

The Java code is then written, but errors are found. Due to the lack of language packs in the/mnt/sdcard/directory, the following two language packs will be placed below the root directory of the SD card (tessdata).

ImportCom.googlecode.tesseract.android.TessBaseAPI;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.os.Bundle;ImportAndroid.util.Log; Public classMainactivityextendsActivity {Private Static FinalString Tessbase_path = "/mnt/sdcard/"; Private Static FinalString default_language = "Eng"; Private Static FinalString chinese_language = "Chi_sim"; Private Static FinalString TAG = "Tesseract"; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); Tessbaseapi Baseapi=NewTessbaseapi ();          Baseapi.init (Tessbase_path, default_language);                 Baseapi.setpagesegmode (Tessbaseapi.psm_auto); //get a picture from a resourceBitmap Bitmap = Bitmapfactory.decoderesource (mainactivity. This. Getresources (), R.DRAWABLE.OCR);                         Baseapi.setimage (bitmap); FinalString Outputtext =Baseapi.getutf8text (); LOG.I (TAG,"Recognition Result:" +outputtext);            Baseapi.end (); }    }

Original:

Recognition results:

Use of tesseract for Android text recognition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.