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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_18730505/article/details/81705319

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都是 没有正确 配置。

扫描二维码关注公众号,回复: 4352572 查看本文章

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();
}

 识别图片

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

猜你喜欢

转载自blog.csdn.net/qq_18730505/article/details/81705319