Windows7 使用tess4j OCR识别

该文档产生的原因: windows7 使用 tess4j 对PDF文件识别时, DLL本地库缺少东西

解决方案: 降低tess4j 版本, 由4.1.0 降低到3.4.1, 其中3.4.1 版本需要一些修改化配置

java 环境: StringBoot3.x JDK21

Windows7 环境部署使用依赖

   <properties>
        <pdfbox.version>2.0.5</pdfbox.version>
        <tess4j.version>3.4.1</tess4j.version>
        <commons-io.version>2.8.0</commons-io.version>
    </properties>


<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>pdfbox</artifactId>
    <version>${pdfbox.version}</version>
</dependency>
<dependency>
    <groupId>net.sourceforge.tess4j</groupId>
    <artifactId>tess4j</artifactId>
    <version>${tess4j.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>

字体库配置

yaml或nacos配置

# orc
tess4j:
  data-path: E://tessdata//fiel
  language: chi_sim

在E盘创建字体库

# 下面放字体库
# 第二个 tessdata目录是必需存在, 如果不存在,会报路径error的错误
E:\tessdata\fiel\tessdata

3.4.1 的字体库

链接:https://pan.baidu.com/s/1UIXQ2w9zwNQJ9m7tJoMg_w 
提取码:5ci8 

环境变量配置

# 键
TESSDATA_PREFIX
# 值
E:\tessdata\fiel

# Path中添加 
%TESSDATA_PREFIX%;

客户端代码

@ConfigurationProperties(prefix = "tess4j")
@Component
@Getter
@Setter
public class Tess4jClient {

    private String dataPath;
    private String language;

    // 入参:图片流
    public String doOcr(BufferedImage image) throws TesseractException {
        //创建Tesseract对象
        ITesseract tesseract = new Tesseract();
        //设置中文字体库路径
        tesseract.setDatapath(dataPath);
        //中文识别
        tesseract.setLanguage(language);
        //执行ocr识别
        String result = tesseract.doOCR(image);
        //替换回车和tal键  使结果为一行
        result = result.replaceAll("\\r|\\n", "-").replaceAll(" ", "");
        return result;
    }
    }

其它参考资料

API:https://tess4j.sourceforge.net/docs/

字体库下载地址: https://gitcode.com/gh_mirrors/te/tessdata/overview?utm_source=csdn_github_accelerator&isLogin=1

Windows7 上安装的就是C++2013, 所以选择3.4.1版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值