JAVA Tesseract OCR引擎

Tess4j是一个基于Tesseract OCR引擎的Java库, Tesseract库最初由惠普实验室于1985年开发,后来被Google收购并于2006年开源。识别效果不好,速度还慢,但是好早好早了。

一、POM依赖

XML 复制代码
   <!--OCR识别
        https://digi.bib.uni-mannheim.de/tesseract/tessdata_fast/ 训练文件下载
        -->
        <dependency>
            <groupId>net.sourceforge.tess4j</groupId>
            <artifactId>tess4j</artifactId>
            <version>5.12.0</version>            
        </dependency>

        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.14.0</version>
        </dependency>

记的要下载训练文件 chi_sim.traineddata

二、配置文件 TesseractOcrConfiguration

java 复制代码
import cn.cakeerp.util.StrUtil;
import net.sourceforge.tess4j.Tesseract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TesseractOcrConfiguration {

    @Bean
    public Tesseract tesseract() {
        Tesseract tesseract = new Tesseract();
        // 设置训练数据文件夹路径
        tesseract.setDatapath(StrUtil.erpConfig.getTraineddata());
        // 设置为中文简体
        tesseract.setLanguage("chi_sim");
        return tesseract;
    }
}

三、使用

java 复制代码
    @Resource
    private Tesseract tesseract;

    //直接就可以识别,也可以
    System.out.println(tesseract.doOCR(new File("d:\\2.jpg")));

    //也可以从 MultipartFile imageFile 里面识别

        InputStream is = null;
        try {
            is = new ByteArrayInputStream(imageFile.getBytes());
            BufferedImage bufferedImage = ImageIO.read(is);
            String textStr = tesseract.doOCR(bufferedImage);
            if (null == textStr || textStr.trim().equals("")) {
                return JsonResult.failed("识别失败,结果为空.");
            }          
            log.error("识别内容为:{}", textStr);
            return JsonResult.failed("未识别到订单号", -1);
        } catch (Exception e) {
            return JsonResult.failed(e.getMessage(), -1);
        } finally {
            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

后续 在官方的仓库中下载到了最新的训练文件 50.2MB结果测试效果还是没啥变化,里面也没有什么可配置的参数。不知道别人怎么用呢。

tessdoc/Data-Files.md at main · tesseract-ocr/tessdoc · GitHub

相关推荐
财税数字化6 小时前
日韩泰票据与欧美发票混合入账怎么选?开灵科技与海外厂商优劣势对比
大数据·人工智能·科技·ocr·软件选型·票据识别
夏悠2 天前
安装PaddlePaddle进行本地OCR教程及避坑指南
人工智能·ocr·paddlepaddle
Hello_Pyhx2 天前
屏译 v0.4.7 配置教程:从截屏授权到 OCR 与翻译排障
ocr
楚识科技2 天前
合同管理 OCR 技术深度解析:从文字识别到智能比对的企业级落地
ocr
AI人工智能+2 天前
通用表格识别技术如何通过五步AI流程,实现对复杂真实表格的智能解析
人工智能·深度学习·ocr·表格识别
深圳市快瞳科技有限公司3 天前
人车准入审核的工程实现:证件OCR、联网查验与业务决策
计算机视觉·ocr·vin码查询·车辆证件ocr·车辆信息查验·汽车ocr
开开心心就好3 天前
白天晚上自动调蓝光,护眼工具亮度可调
服务器·开发语言·算法·pdf·ocr·intellij-idea·idea
开开心心就好3 天前
安卓PDF处理工具,免费无广告零弹窗
android·服务器·开发语言·算法·pdf·ocr
开开心心就好5 天前
多份文档怎么批量打印?支持多种格式
java·服务器·开发语言·pdf·ocr·散列表·启发式算法
开开心心就好5 天前
文件被占用删不掉?解锁工具强制删除
java·运维·服务器·开发语言·前端·pdf·ocr