(Reproduced Annotated Source: Http://blog.csdn.net/buptgshengod)
1. Introduction
Fast New Year, Bo Master of the application of the screen to take the words of reading glasses coding work is also in intensive progress. Here's a look at the core functional OCR in this application, which is the function of image recognition. Let's take a look at my implementation results. It's an English-language page that's been cut off on the internet, and it's my app's implementation.
2. Implement
(1) First to download my source code and language pack, the blog will give the address below. (The source is set to 10 points, is to let everyone cherish the fruits of other people's Labor)
(2) Import two folders and jar files from the Lib in the code.
(3) Two points to note please take a look at the comments of the code posted below
Packagecom.example.tess; ImportJava.io.File; ImportCom.googlecode.tesseract.android.TessBaseAPI; ImportAndroid.os.Bundle; Importandroid.app.Activity; Importandroid.content.Intent; ImportAndroid.graphics.Bitmap; Importandroid.graphics.BitmapFactory; ImportAndroid.view.Menu; ImportAndroid.view.View; ImportAndroid.view.View.OnClickListener; ImportAndroid.widget.Button; ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {PrivateTextView text; Tessbaseapi Baseapi; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Button BT=NewButton (Getbasecontext ()); BT=(Button) Findviewbyid (R.id.button1); Text=NewTextView (Getbasecontext ()); Text=(TextView) Findviewbyid (R.ID.TEXTVIEW1); Baseapi=NewTessbaseapi (); //(note) The previous address is the parent of the language pack. Eng says the parsing is in EnglishBaseapi.init ("/mnt/sdcard/tesseract/", "Eng"); Bt.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View sourse) {//text.settext ("SB"); //set the image bitmap to be OCR, the image address to parse (note)Baseapi.setimage (Getdiskbitmap ("/mnt/sdcard/mypic.bmp")); //get the OCR string based on the init languageString text1=Baseapi.getutf8text (); Text.settext (Text1); //Release Bitmapbaseapi.clear (); } } ); } /** Convert local image to bitmap*/ PrivateBitmap Getdiskbitmap (String pathstring) {Bitmap Bitmap=NULL; Try{File File=NewFile (pathstring); if(File.exists ()) {bitmap=Bitmapfactory.decodefile (pathstring); } } Catch(Exception e) {//Todo:handle Exception } returnbitmap; } }
(4) The larger the picture takes, the longer it takes, this example takes almost half a minute
3. Source code and related documents
Free of charge which Tess folder is the Android program Tessdata is the language pack
4. Chinese recognition
You can download it at the following address, unzip it under/tesseract/tessdata, and change Eng to Chi_sim
Chi_sim.traineddata.gz Chinese Language Pack
If you do not have access to Google URLs, please refer to another blog: Modify the computer hosts login Google Web "for learning only"-to a link to another site blog
* * Note: This blog by the Great God published and reproduced, if asked to the original blogger blog under the question (can also leave the question to a learning opportunity < (^-^) >)
Android TESSERACT-OCR Example tutorial (including Chinese recognition) (with source)--Reprint