springboot整合Tesseract提取图片文字

1、引入tess4j依赖

        <dependency>
            <groupId>net.sourceforge.tess4j</groupId>
            <artifactId>tess4j</artifactId>
            <version>5.11.0</version>
        </dependency>

2、在项目resources下创建tessdata文件夹

在这里插入图片描述

3、引入语言包

可以在我的百度网盘上提取,进入网盘
(链接: https://pan.baidu.com/s/17TiWby83LTK0cL8XXG_mUw?pwd=nd2d 提取码: nd2d )
中文字库 chi_sim.traineddata ,英文字库 eng.traineddata

4、测试类

    @SneakyThrows
    public static void main(String[] args) throws Exception {
        File imageFile = new File("C:\\Users\\Administrator\\Desktop\\1722237818223.png");
        Tesseract tesseract = new Tesseract();
        //设置 tessdata 目录
        tesseract.setDatapath("wms/src/main/resources/tessdata");
        //设置语言 中文
        tesseract.setLanguage("chi_sim");
        try {
            String extractedText = tesseract.doOCR(imageFile);
            System.out.println(extractedText);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }

测试文章图片及代码解析结果
测试文章图片及代码解析结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值