Sping boot 图像文字识别Tesseract(OCR)

使用场景:随着人工智能的发展,生活中也逐渐出现了很多便捷高效的应用,人脸识别、证件识别认证、名片识别、车牌识别等,都在方便着我们的日常生活。同样,这些技术也可以为我们的日常业务处理流程提供智能高效的解决方案。日常交易、清算业务往来存在各种电子邮件、传真等单据,主要有确认成交单据、定存协议、对敲指令、银行间费用、网下中签公告、境外券商确认单等。这些单据需要人工识别提取要素录入系统,通过使用OCR技术,对单据图像内容进行识别、矫正,提取关键字段元素,与相关系统连接,能够减少人工手动录入,提高工作效率,降低人工录入失误。

Tesseract-OCR(包含官方中文识别包,需自行配置环境变量路径到 tessdata)

阿里云盘分享

提取码:v18l

    public static String FindOCR(String srImage, boolean zh) {
        try {
            System.out.println("识别");
            File imageFile = new File(srImage);
            if (!imageFile.exists()) {
                return "图片不存在";
            }
            BufferedImage textImage = ImageIO.read(imageFile);
            textImage = ImageHelper.convertImageToGrayscale(textImage);// 黑白处理
//            textImage = textImage.getSubimage(0,0,300,80);//截图图片
            textImage = ImageHelper.getScaledInstance(textImage, textImage.getWidth() * 10, textImage.getHeight() * 10);//放大图片识别
            Tesseract instance = Tesseract.getInstance();
            instance.setDatapath("C:\\Program Files (x86)\\Tesseract-OCR\\tessdata");//设置训练库
            if (zh)
                instance.setLanguage("chi_sim");//中文识别
            String result = null;
            result = instance.doOCR(textImage);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return "识别失败";
        }
    }

    public static void main(String[] args) throws Exception {
        String result = FindOCR("D:\\WWWROOTYYKJ\\oc\\1111111111111111111111111111111111111.png", true);

        System.out.println(result);
    }

    public static String FindOCR(String srImage, boolean zh) {
        try {
            System.out.println("识别");
            File imageFile = new File(srImage);
            if (!imageFile.exists()) {
                return "图片不存在";
            }
            BufferedImage textImage = ImageIO.read(imageFile);
            textImage = ImageHelper.convertImageToGrayscale(textImage);// 黑白处理
//            textImage = textImage.getSubimage(0,0,300,80);//截图图片
            textImage = ImageHelper.getScaledInstance(textImage, textImage.getWidth() * 10, textImage.getHeight() * 10);//放大图片识别
            Tesseract instance = Tesseract.getInstance();
            instance.setDatapath("C:\\Program Files (x86)\\Tesseract-OCR\\tessdata");//设置训练库
            if (zh)
                instance.setLanguage("chi_sim");//中文识别
            String result = null;
            result = instance.doOCR(textImage);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return "识别失败";
        }
    }

    public static void main(String[] args) throws Exception {
        String result = FindOCR("D:\\WWWROOTYYKJ\\oc\\1111111111111111111111111111111111111.png", true);

        System.out.println(result);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值