﻿{"id":1645,"date":"2024-03-12T10:52:50","date_gmt":"2024-03-12T02:52:50","guid":{"rendered":"http:\/\/blog.sway.com.cn\/?p=1645"},"modified":"2024-03-12T10:53:03","modified_gmt":"2024-03-12T02:53:03","slug":"springboot%e9%a1%b9%e7%9b%ae%e4%bd%bf%e7%94%a8tesseract","status":"publish","type":"post","link":"http:\/\/blog.sway.com.cn\/?p=1645","title":{"rendered":"SpringBoot\u9879\u76ee\u4f7f\u7528tesseract"},"content":{"rendered":"\n<p>\u5b98\u65b9github\u5730\u5740\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/tesseract-ocr\/tesseract\">https:\/\/github.com\/tesseract-ocr\/tesseract<\/a><\/p>\n\n\n\n<p>\u6ce8\u610f\uff0ctess4j\u4e2d\u7528\u5230\u7684JAI\u7c7b\u5e93\u53ea\u652f\u6301\u4ee5\u4e0b\u56fe\u50cf\u7c7b\u578b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1-1024x540.png\" alt=\"\" class=\"wp-image-1647\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1-1024x540.png 1024w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1-300x158.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1-768x405.png 768w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1.png 1327w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>\u8be6\u60c5\u53ef\u5230\u8fdb\u5165\u4e0b\u9762\u94fe\u63a5\u67e5\u770b\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/jai-imageio\/jai-imageio-core\">https:\/\/github.com\/jai-imageio\/jai-imageio-core<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b89\u88c5\u7cfb\u7edf\u73af\u5883\uff08\u53ef\u9009\uff09<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/UB-Mannheim\/tesseract\/wiki\">https:\/\/github.com\/UB-Mannheim\/tesseract\/wiki<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"414\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1024x414.png\" alt=\"\" class=\"wp-image-1646\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-1024x414.png 1024w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-300x121.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-768x310.png 768w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image.png 1391w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>\u5982\u679c\u4e0d\u5b89\u88c5\uff0c\u5219\u4f1a\u5728\u6267\u884cOCR\u8bc6\u522b\u65f6\u51fa\u73b0\u5982\u4e0b\u4f5c\u7269\u63d0\u793a\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I\/O package.\nhttps:\/\/github.com\/jai-imageio\/jai-imageio-core\n\tat net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:215) ~[tess4j-4.5.5.jar:4.5.5]\n\tat net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:195) ~[tess4j-4.5.5.jar:4.5.5]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e0b\u8f7d\u8bed\u8a00\u6570\u636e<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/tesseract-ocr\/tessdata\">https:\/\/github.com\/tesseract-ocr\/tessdata<\/a><\/p>\n\n\n\n<p>\u5230\u8fd9\u4e2a\u8fde\u63a5\u4e2d\uff0c\u4e0b\u8f7dzip\u5305\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"443\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2-1024x443.png\" alt=\"\" class=\"wp-image-1648\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2-1024x443.png 1024w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2-300x130.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2-768x332.png 768w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2-1536x664.png 1536w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-2.png 2021w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>\u505aOCR\u8bc6\u522b\u4e4b\u524d\uff0c\u4e0d\u914d\u7f6etessdata\u7684\u8bdd\uff0c\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"167\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-3.png\" alt=\"\" class=\"wp-image-1649\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-3.png 972w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-3-300x52.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2024\/03\/image-3-768x132.png 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><\/a><\/figure>\n\n\n\n<p>\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u53ea\u4e0b\u8f7deng.traineddata<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f15\u5165\u4f9d\u8d56<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/OCR\u4f9d\u8d56\nimplementation 'net.sourceforge.tess4j:tess4j:4.5.5'\n\n\/\/JAI Image I\/O \u6269\u5c55\u5e93\nimplementation group: 'com.github.jai-imageio', name: 'jai-imageio-jpeg2000', version: '1.4.0'<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee3\u7801\u793a\u4f8b<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        File ocrFile = new File(\"ocr.png \");\n        \/\/\u4f7f\u7528OCR\u63d0\u53d6\u56fe\u7247\u6587\u5b57\n        Tesseract tesseract = new Tesseract();\n        \/\/\u8bbe\u7f6e Tesseract \u6570\u636e\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u5982\u679c\u4e0d\u662f\u9ed8\u8ba4\u8def\u5f84\u7684\u8bdd\n        \/\/tesseract.setDatapath(\"path_to_your_tessdata_folder\");\n        try {\n            String result = tesseract.doOCR(ocrFile);\n            System.out.println(result);\n        } catch (TesseractException e) {\n            System.err.println(e.getMessage());\n        }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5176\u4ed6<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I\/O package.\nhttps:\/\/github.com\/jai-imageio\/jai-imageio-core\n\tat net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:215) ~[tess4j-4.5.5.jar:4.5.5]\n\tat net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:195) ~[tess4j-4.5.5.jar:4.5.5]<\/pre>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u6ce8\u610f\u4e00\u4e0b\u662f\u5426\u4f60\u7684\u56fe\u50cf\u7c7b\u578b\u4e0d\u5c5e\u4e8e\u652f\u6301\u7684\u8303\u56f4\uff0c\u8bf7\u67e5\u770bJAI\u7684\u5b98\u7f51\u94fe\u63a5\uff0c\u522b\u6000\u7591\uff0cPNG\u548cJPG\u90fd\u662f\u4e0d\u652f\u6301\u7684~\uff01<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u65b9github\u5730\u5740\uff1a https:\/\/github.com\/tesseract-ocr\/tesseract  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1645","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1645"}],"version-history":[{"count":3,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1645\/revisions"}],"predecessor-version":[{"id":1652,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1645\/revisions\/1652"}],"wp:attachment":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1645"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}