介紹 此應用程序使用Tesseract 3的Tesseract OCR引擎,該引擎經過識別字符模式( https://github.com/tesseract-ocr/tesseract )來工做。 Tesseract具備unicode(UTF-8)支持,能夠開箱即用識別100多種語言。 背景 我嘗試了Google文本識別API- https://deveandroid
此應用程序使用Tesseract 3的Tesseract OCR引擎,該引擎經過識別字符模式(https://github.com/tesseract-ocr/tesseract)來工做。Tesseract具備unicode(UTF-8)支持,能夠「開箱即用」識別100多種語言。git
我嘗試了Google文本識別API- https://developers.google.com/vision/android/text-overview,但它不適合我,因此我找到了這個驚人的引擎。github
開始吧!在Android studio中建立一個新項目(我使用的是3.2.1版),或者您能夠下載源文件並選擇:File-New-Import項目。ide
添加到build.gradle
應用程序級別:函數
implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' implementation 'com.rmtheis:tess-two:9.0.0'
我使用Butterknife
庫,它很是有用,主庫是 - ' tess-two:9.0.0
'' - 它包含一個Android的Tesseract工具(tesseract-android-tools)的分支,它增長了一些額外的功能。此外,咱們須要相機和寫入權限,所以將其添加到AndroidManifest.xml。工具
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:name="android.hardware.camera" /> <uses-permission android:name="android.permission.CAMERA" />
作一個簡單的佈局文件Button
,TextView
而且ImageView
:佈局
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <Button android:id="@+id/scan_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"