Android TESSERACT-OCR Example tutorial (with Chinese recognition) (with source)

Source: Internet
Author: User

(Reproduced Please specify 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 [Java]View Plaincopy
  1. Package com.example.tess;
  2. Import Java.io.File;
  3. Import Com.googlecode.tesseract.android.TessBaseAPI;
  4. Import Android.os.Bundle;
  5. Import android.app.Activity;
  6. Import android.content.Intent;
  7. Import Android.graphics.Bitmap;
  8. Import Android.graphics.BitmapFactory;
  9. Import Android.view.Menu;
  10. Import Android.view.View;
  11. Import Android.view.View.OnClickListener;
  12. Import Android.widget.Button;
  13. Import Android.widget.TextView;
  14. Public class Mainactivity extends Activity {
  15. private TextView text;
  16. Tessbaseapi Baseapi;
  17. @Override
  18. protected void OnCreate (Bundle savedinstancestate) {
  19. super.oncreate (savedinstancestate);
  20. Setcontentview (R.layout.activity_main);
  21. Button bt=New button (Getbasecontext ());
  22. bt= (Button) Findviewbyid (R.id.button1);
  23. text=New TextView (Getbasecontext ());
  24. text= (TextView) Findviewbyid (R.ID.TEXTVIEW1);
  25. baseapi=new Tessbaseapi ();
  26. //(note) The previous address is the parent of the language pack. Eng says the parsing is in English
  27. Baseapi.init ("/mnt/sdcard/tesseract/", "Eng");
  28. Bt.setonclicklistener (new Onclicklistener () {
  29. @Override
  30. public void OnClick (View sourse) {
  31. //Text.settext ("SB");
  32. //Set the image bitmap to be OCR, the image address to parse (note)
  33. Baseapi.setimage (Getdiskbitmap ("/mnt/sdcard/mypic.bmp"));
  34. //Based on the Init language, get the OCR string
  35. String text1= Baseapi.getutf8text ();
  36. Text.settext (Text1);
  37. //Release bitmap
  38. Baseapi.clear ();
  39. }
  40. }
  41. );
  42. }
  43. /* 
  44. * Convert local image to bitmap
  45. */
  46. private Bitmap Getdiskbitmap (String pathstring)
  47. {
  48. Bitmap Bitmap = null;
  49. Try
  50. {
  51. File File = new file (pathstring);
  52. if (file.exists ())
  53. {
  54. Bitmap = Bitmapfactory.decodefile (pathstring);
  55. }
  56. } catch (Exception e)
  57. {
  58. //Todo:handle exception
  59. }
  60. return bitmap;
  61. }
  62. }

(4) The larger the picture takes, the longer it takes, this example takes almost half a minute 3. Source code and related documents  Well, a lot of people say that code can not download or say 10 points too expensive, here to provide free. Where the 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
Http://code.google.com/p/tesseract-ocr/downloads/detail?name=chi_sim.traineddata.gz&can=2&q=

Android TESSERACT-OCR Example tutorial (with Chinese recognition) (with source)

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.