当前位置:   article > 正文

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

springboot tesseract

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

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

阿里云盘分享

提取码:v18l

  1. public static String FindOCR(String srImage, boolean zh) {
  2. try {
  3. System.out.println("识别");
  4. File imageFile = new File(srImage);
  5. if (!imageFile.exists()) {
  6. return "图片不存在";
  7. }
  8. BufferedImage textImage = ImageIO.read(imageFile);
  9. textImage = ImageHelper.convertImageToGrayscale(textImage);// 黑白处理
  10. // textImage = textImage.getSubimage(0,0,300,80);//截图图片
  11. textImage = ImageHelper.getScaledInstance(textImage, textImage.getWidth() * 10, textImage.getHeight() * 10);//放大图片识别
  12. Tesseract instance = Tesseract.getInstance();
  13. instance.setDatapath("C:\\Program Files (x86)\\Tesseract-OCR\\tessdata");//设置训练库
  14. if (zh)
  15. instance.setLanguage("chi_sim");//中文识别
  16. String result = null;
  17. result = instance.doOCR(textImage);
  18. return result;
  19. } catch (Exception e) {
  20. e.printStackTrace();
  21. return "识别失败";
  22. }
  23. }
  24. public static void main(String[] args) throws Exception {
  25. String result = FindOCR("D:\\WWWROOTYYKJ\\oc\\1111111111111111111111111111111111111.png", true);
  26. System.out.println(result);
  27. }

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/620031
推荐阅读
相关标签
  

闽ICP备14008679号