码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 使用 Tess4J 实现本地与远程图片的文字识别


    pom:

    1. <dependency>
    2. <groupId>net.sourceforge.tess4j</groupId>
    3. <artifactId>tess4j</artifactId>
    4. <version>5.11.0</version>
    5. </dependency>

    部分代码:

    1. package com.zy.datapickcli.sys.controller;
    2. import net.sourceforge.tess4j.Tesseract;
    3. import net.sourceforge.tess4j.TesseractException;
    4. import java.io.File;
    5. public class TempTest {
    6. public static void main(String[] args) throws TesseractException {
    7. File file = new File("D:\\1.png");
    8. System.out.println(recognizeText(file));
    9. }
    10. public static String recognizeText(File imageFile) throws TesseractException {
    11. Tesseract tesseract = new Tesseract();
    12. // 设定训练文件的位置(如果是标准英文识别,此步可省略)
    13. tesseract.setDatapath("D:\\tessdata");
    14. tesseract.setLanguage("chi_sim");
    15. return tesseract.doOCR(imageFile);
    16. }
    17. }

    data文件下载地址

    https://gitcode.com/tesseract-ocr/tessdata/tree/main

    其余参考代码:

    1. @Service
    2. public class OcrService {
    3. public String recognizeText(File imageFile) throws TesseractException {
    4. Tesseract tesseract = new Tesseract();
    5. // 设定训练文件的位置(如果是标准英文识别,此步可省略)
    6. tesseract.setDatapath("你的tessdata各语言集合包地址");
    7. tesseract.setLanguage("chi_sim");
    8. return tesseract.doOCR(imageFile);
    9. }
    10. public String recognizeTextFromUrl(String imageUrl) throws Exception {
    11. URL url = new URL(imageUrl);
    12. InputStream in = url.openStream();
    13. Files.copy(in, Paths.get("downloaded.jpg"), StandardCopyOption.REPLACE_EXISTING);
    14. File imageFile = new File("downloaded.jpg");
    15. return recognizeText(imageFile);
    16. }
    17. }

    执行效果:

  • 相关阅读:
    亚像素源码
    uniapp跳转H5外部链接
    基于知识蒸馏的两阶段去雨去雪去雾模型学习记录(三)之知识测试阶段与评估模块
    Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒
    MessagePack 和System.Text.Json 序列化和反序列化对比
    windows环境下node安装教程(超详细)
    目前很火的养猫微信小程序源码带流量主+搭建教程
    六、函数和变量的命名
    手机app开发可选技术——webview
    Spring MVC
  • 原文地址:https://blog.csdn.net/u013008898/article/details/138183432
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号