Java调用tess4j完成 OCR 文字识别

1,新建 maven 工程

2,引入依赖

<dependency>

<groupId>net.sourceforge.tess4j</groupId>

<artifactId>tess4j</artifactId>

<version>5.11.0</version>

</dependency>

3,安装 tesseract-ocr

下载地址https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-5.3.3.20231005.exe

其他版本可以查看 https://digi.bib.uni-mannheim.de/tesseract/

安装过程中一直点下一步,建议取消语言包选项,后面手动下载

可能需要安装visual c++ 2015-2019 redistributable或最新版visual c++ 2015-2022 redistributable

4,下载语言包

https://digi.bib.uni-mannheim.de/tesseract/tessdata_fast/

下载enm.traineddata和chi_sim.traineddata,复制粘贴到C:\Program Files\Tesseract-OCR\tessdata

5,调用 Tesseract API 完成文本识别

import java.io.File;

import net.sourceforge.tess4j.Tesseract;

public class Tess4jDemo {

public static void main(String[] args) {

// 创建实例

Tesseract instance = new Tesseract();

// 设置语言包路径

instance.setDatapath("C:\\Program Files\\Tesseract-OCR\\tessdata");

// 设置语言

instance.setLanguage("chi_sim");

// 设置文本文件

File file = new File("C:\\Users\\user1\\Desktop\\截图.PNG");

try {

// 文本识别

String result = instance.doOCR(file);

System.out.println(result);

} catch (Exception e) {

e.printStackTrace();

}

}

}

示例代码见

https://download.csdn.net/download/daqinzl/89221358

相关推荐
二哈赛车手13 小时前
新人笔记---ApiFox的一些常见使用出错
java·笔记·spring
栗子~~13 小时前
JAVA - 二层缓存设计(本地缓冲+redis缓冲+广播所有本地缓冲失效) demo
java·redis·缓存
YDS82913 小时前
DeepSeek RAG&MCP + Agent智能体项目 —— RAG知识库的搭建和接口实现
java·ai·springboot·agent·rag·deepseek
未若君雅裁15 小时前
MyBatis 一级缓存、二级缓存与清理机制
java·缓存·mybatis
AI人工智能+电脑小能手15 小时前
【大白话说Java面试题 第65题】【JVM篇】第25题:谈谈对 OOM 的认识
java·开发语言·jvm
阿维的博客日记16 小时前
Nacos 为什么能让配置动态生效?(涉及 @RefreshScope 注解)
java·spring
雨辰AI16 小时前
SpringBoot3 + 人大金仓读写分离 + 分库分表 + 集群高可用 全栈实战
java·数据库·mysql·政务
辰海Coding17 小时前
MiniSpring框架学习-完成的 IoC 容器
java·spring boot·学习·架构
小小编程路17 小时前
C++ 多线程与并发
java·jvm·c++
AI视觉网奇17 小时前
linux 检索库 判断库是否支持
java·linux·服务器