{"id":988,"date":"2023-03-12T00:24:04","date_gmt":"2023-03-11T16:24:04","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=988"},"modified":"2023-04-29T13:22:30","modified_gmt":"2023-04-29T05:22:30","slug":"use-tesseract-to-recognize-text-on-android","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/use-tesseract-to-recognize-text-on-android\/","title":{"rendered":"Android\u4e0a\u4f7f\u7528Tesseract\u8bc6\u522b\u6587\u5b57"},"content":{"rendered":"<p>\u6587\u5b57\u8bc6\u522b\u4e00\u822c\u4f7f\u7528\uff1atesseract-ocr<br \/>\nGitHub\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/tesseract-ocr\/tesseract\">https:\/\/github.com\/tesseract-ocr\/tesseract<\/a><br \/>\n\u8bad\u7ec3\u6570\u636e\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/tesseract-ocr\/tessdata\">https:\/\/github.com\/tesseract-ocr\/tessdata<\/a><\/p>\n<p>Android\u5e73\u53f0\u63a8\u8350\u7684tesseract\u5c01\u88c5\uff1atess-two<br \/>\nGitHub\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/rmtheis\/tess-two\">https:\/\/github.com\/rmtheis\/tess-two<\/a><\/p>\n<p><!-- more --><\/p>\n<h3>Tesseract\u53catess-two\u7b80\u4ecb<\/h3>\n<p>Tesseract\u662f\u4e00\u4e2aHP\u548cGoogle\u5148\u540e\u7ef4\u62a4\u7684\u5f00\u6e90OCR\uff08Optical Character Recognition\uff09\u5f15\u64ce\uff0c3.0\u4ee5\u540e\u5df2\u7ecf\u652f\u6301\u4e2d\u6587\u8bc6\u522b\u3002tess-two\u662f\u4e00\u4e2a\u5728Android\u4e0a\u4f7f\u7528tesseract\u7684\u5b9e\u4f8b\uff0ctess-two\u4e2d\u6709\u4e09\u4e2a\u4e3b\u8981\u76ee\u5f55\uff1a<\/p>\n<ul>\n<li>eyes-two\uff1a\u5bf9leptonica\u7684\u5c01\u88c5<\/li>\n<li>tess-two\uff1a\u5bf9Tesseract\u7684\u5c01\u88c5<\/li>\n<li>tess-two-test\uff1aocr\u7684\u6d4b\u8bd5\u4ee3\u7801<\/li>\n<\/ul>\n<h3>\u83b7\u53d6tess-two<\/h3>\n<pre><code>git clone https:\/\/github.com\/rmtheis\/tess-two.git<\/code><\/pre>\n<p>\u6216<\/p>\n<pre><code>dependencies {\n    implementation &#039;com.rmtheis:tess-two:9.0.0&#039;  \/\/\u514d\u7f16\u8bd1\u65b9\u5f0f\n}<\/code><\/pre>\n<h3>\u4f7f\u7528ndk\u7f16\u8bd1tess-two\u548ceyes-two<\/h3>\n<pre><code>cd tess-two\nndk-build<\/code><\/pre>\n<pre><code>cd eyes-two\nndk-build<\/code><\/pre>\n<h3>\u7b80\u5355\u8c03\u7528\u793a\u4f8b<\/h3>\n<p>\u53ea\u9700\u8981\u65b0\u5efaModule\u5bfc\u5165tess-two\u4e2d\u7684tess-two\u5373\u53ef\uff0c\u7136\u540e\u5f15\u7528\u8fd9\u4e2aLibrary<\/p>\n<pre><code class=\"language-java\">\/\/SD\u5361\u8def\u5f84\nprivate static final String SD_PATH = Environment.getExternalStorageDirectory();\n\/\/\u5b57\u5178\u540d\nprivate static final String DICTIONARY = &quot;\/custom&quot;;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    TessBaseAPI baseApi = new TessBaseAPI();\n    \/\/\u8bb0\u5f97\u8981\u5728SD\u5361\u7684tessdata\u6587\u4ef6\u5939\u4e0b\u653e\u5bf9\u5e94\u7684\u5b57\u5178\u6587\u4ef6\uff0c\u4f8b\u5982\u8fd9\u91cc\u5c31\u653e\u7684\u662fcustom.traineddata\n    baseApi.init(SD_PATH, DICTIONARY);\n    baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO);\n    \/\/\u8bb0\u5f97\u8981\u5728\u5bf9\u5e94\u7684\u6587\u4ef6\u5939\u91cc\u653e\u4e0a\u8981\u8bc6\u522b\u7684\u56fe\u7247\u6587\u4ef6\uff0c\u6bd4\u5982\u8fd9\u91cc\u5c31\u5728SD\u5361\u6839\u76ee\u5f55\u653e\u4e86test.png\n    baseApi.setImage(new File(SD_PATH + &quot;\/test.png&quot;));\n    final String result= baseApi.getUTF8Text();\n    \/\/\u53ef\u4ee5\u628aresult\u7684\u503c\u8d4b\u503c\u7ed9\u4f60\u7684TextView\n    baseApi.end();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u5b57\u8bc6\u522b\u4e00\u822c\u4f7f\u7528\uff1atesseract-ocr GitHub\uff1ahttps:\/\/github.com\/tesser [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[274,273],"class_list":["post-988","post","type-post","status-publish","format-standard","hentry","category-android-ndk","tag-ocr","tag-tesseract"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}