From e44b9e30adbecf70ca166e13db3cd3246cab5a88 Mon Sep 17 00:00:00 2001 From: Jarrett <291979254@qq.com> Date: Sat, 17 Feb 2024 19:03:52 +0800 Subject: [PATCH] add: fix pic executor --- README.md | 5 ++-- README_CH.md | 10 +++----- .../java/com/jiaruiblog/util/OcrUtil.java | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 48d7cd7..e23d0b8 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ read [open issues](https://github.com/othneildrew/Best-README-Template/issues) You can join our Wechat group if you are interested. -imGroup +imGroup > If you have any requirements for customization or private deployment, please feel free to contact me. @@ -188,8 +188,7 @@ Jarrett Luo - luojiarui2@163.com If you find the project valuable, your support and appreciation are welcome! -wechat -wechat +imGroup diff --git a/README_CH.md b/README_CH.md index eb8f575..d3d494d 100644 --- a/README_CH.md +++ b/README_CH.md @@ -158,11 +158,9 @@ https://github.com/Jarrettluo/document-sharing-site.git ## 提交代码 -目前仍然存在很多问题,欢迎一起来贡献! +欢迎加入微信交流群,一起玩😄,如果微信群二维码失效,可以加我微信拉你进群。 -加入微信群,一起玩😄 - -imGroup +imGroup > 如果有二次开发或者私有部署需求,请联系我 @@ -193,9 +191,7 @@ https://github.com/Jarrettluo/document-sharing-site.git Jarrett Luo - luojiarui2@163.com 如果您觉得项目不错,欢迎赞赏支持! - -wechat -wechat +imGroup diff --git a/src/main/java/com/jiaruiblog/util/OcrUtil.java b/src/main/java/com/jiaruiblog/util/OcrUtil.java index 84d69ea..921c210 100644 --- a/src/main/java/com/jiaruiblog/util/OcrUtil.java +++ b/src/main/java/com/jiaruiblog/util/OcrUtil.java @@ -10,6 +10,8 @@ /** * 如果未将tessdata放在根目录下需要指定绝对路径 * instance.setDatapath("the absolute path of tessdata"); + * 对应的动态连接库下载地址: + * Downloads are available here https://github.com/ollydev/libtesseract/releases * @ClassName OCRUtil * @Description orc 离线识别 * @Author luojiarui @@ -50,6 +52,28 @@ private static void tess4j() throws TesseractException, IOException { } + public static void xx() { + try { + // TODO 该种方法只支持在windows下进行,而linux下需要so的动态连接库 + // https://blog.csdn.net/qq_62357662/article/details/132430352 + //获取本地图片 + File file = new File("D:\\测试\\测试.png"); + //创建Tesseract对象 + ITesseract tesseract = new Tesseract(); + //设置字体库路径 (你的chi_sim.traineddata放的个文件夹 + tesseract.setDatapath("D:\\Tess4J\\tessdata"); + //中文识别 chi_sim.traineddata的前缀 + tesseract.setLanguage("chi_sim"); + //执行ocr识别 + String result = tesseract.doOCR(file); + //替换回车和tal键 使结果为一行 + result = result.replaceAll("\\r|\\n","-").replaceAll(" ",""); + System.out.println("识别的结果为:"+result); + } catch (Exception e) { + e.printStackTrace(); + } + } + public static void main(String[] args) throws TesseractException, IOException { tess4j(); }