关于使用tess4j-OCR识别图片中文教程,亲测可用,不报错

tess4j是hp 在20sh世纪90年代研发,最后贡献给google 的 开源项目

自 版本3.0.2后支持了对中文字库的识别

jar包最简单的获取方式

idea 创建maven工程在pom.xml引入 tess4j

<!-- https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j -->
<dependency>
    <groupId>net.sourceforge.tess4j</groupId>
    <artifactId>tess4j</artifactId>
    <version>3.2.1</version>
</dependency>

等待下载完对应的jar包。去本地仓库考出下载的jar包,去重jar包如下

1、在src同级目录创建 tessdata文件夹,将tess4j.jar解压缩。把解压后的tessdata中的内容一律拷贝进来。

2、我们使用的是tess4j。jna封装的 那些 c++写的 动态类库 dll文件 已经在jar包里了。不要在像网上的教程 安装一下 ,不需要安装

3、从github上下载对应的语言包。我需要识别中文所以下载语言包 chi_sim

https://github.com/tesseract-ocr/tessdata

4、如果报错绝逼 99.99都是 没有正确 配置。

5、jdk 版本必须1.7以上

测试

public static void main(String args[]) {
    File imageFile = new File("C:\\Users\\yzx\\Desktop\\test\\t2.png");
    ITesseract instance = new Tesseract();  // JNA Interface Mapping
    // ITesseract instance = new Tesseract1(); // JNA Direct Mapping

    instance.setLanguage("chi_sim");
    try {
        String result = instance.doOCR(imageFile);
        System.out.println(result);
    } catch (TesseractException e) {
        System.err.println(e.getMessage());
    }
    //excute();
}

 识别图片

识别率不算特别高。凑合。毕竟开源的东西。要求不要太高。感兴趣的可以研究一下训练字库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值