Android tesseract-ocr instance tutorial (source code)

Source: Internet
Author: User

 

The Chinese New Year is approaching, and the new application of the blogger-screen word-taking-the-old image coding work is also in full swing. Next we will share with you the core feature ocr in this application, that is, the image recognition function. Let's take a look at my implementation results. It is an English page that is randomly cut off on the Internet. It is the Implementation Effect of my application.

 

2. Implementation (1) first download my source code and Language Pack. The address is provided below the blog. (The source code is set to 10 points to let everyone cherish the fruits of others' work) (2) import the two folders and jar files in the lib in the code. (3) Pay attention to the following two points. Please carefully read the comments of the code below.
Package com. example. tess; import java. io. file; import com. googlecode. tesseract. android. tessBaseAPI; import android. OS. bundle; import android. app. activity; import android. content. intent; import android. graphics. bitmap; import android. graphics. bitmapFactory; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. textView; p Ublic class MainActivity extends Activity {private TextView text; TessBaseAPI baseApi; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); Button bt = new Button (getBaseContext (); bt = (Button) findViewById (R. id. button1); text = new TextView (getBaseContext (); text = (TextView) findViewById (R. id. textView1); baseApi = new TessBa The address before seAPI (); // (Note) is the parent level of the Language Pack. Eng indicates that the English baseApi is parsed. init (/mnt/sdcard/tesseract/, eng); bt. setOnClickListener (new OnClickListener () {@ Override public void onClick (View sourse) {// text. setText (sb); // sets the bitmap of the image to be ocr. The address of the image to be parsed (Note) is baseApi. setImage (getDiskBitmap (/mnt/sdcard/mypic.bmp); // obtain the String text1 = baseApi after ocr Based on the Init language. getUTF8Text (); text. setText (text1); // release bitmap baseApi. clear () ;}}) ;}/ ** converts a local image to bitmap */private Bitmap getDiskBitmap (String pathString) {Bitmap bitmap = null; try {File file = new File (pathString); if (file. exists () {bitmap = BitmapFactory. decodeFile (pathString) ;}} catch (Exception e) {// TODO: handle exception} return bitmap ;}}

(4) The larger the image, the longer it takes. In this example, it takes about half a minute. 3. source code and Related Files Instance source code
Language Pack eng

Related Article

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.