OCR识别PDF文件

您所在的位置:网站首页 ocr识别pdf表格 OCR识别PDF文件

OCR识别PDF文件

2023-11-13 16:47| 来源: 网络整理| 查看: 265

1现有解析pdf的方法 使用org.apache.pdfbox读取pdf,只能读取pdf中的文字,有些纸件扫描成的pdf文字会错乱,有些字还是图片的方式显示的,导致读取的内容不全,常常会获取不到想要的数据。

2 OCR文字识别 pdf需要转换为图片,进行识别,识别率高。

2.1 调用百度接口 优点:识别率高,识别速度快

缺点:按次收费

2.2 使用开源工具读取pdf文档 2.2.1 下载工具包 https://github.com/tesseract-ocr/tessdata 下载chi_sim.traineddata,chi_sim_vert.traineddata

2.2.2 添加依赖

net.sourceforge.tess4j tess4j 4.4.0

2.2.3 编写程序

import net.sourceforge.tess4j.Tesseract; import net.sourceforge.tess4j.TesseractException; public class TestTess { public static void main(String[] args) { // 识别图片的路径(修改为自己的图片路径) String path = "C:\\work\\notebook\\prototype\\target\\qq1.jpg"; // 语言库位置(修改为跟自己语言库文件夹的路径) // String lagnguagePath = "C:\\work\\projects\\tess\\resources\\tessdata"; File file = new File(path); ITesseract instance = new Tesseract(); //设置训练库的位置 //instance.setDatapath(lagnguagePath); //chi_sim :简体中文, eng 根据需求选择语言库 instance.setLanguage("chi_sim"); String result = null; try { long startTime = System.currentTimeMillis(); result = instance.doOCR(file); long endTime = System.currentTimeMillis(); System.out.println("Time is:" + (endTime - startTime) + " 毫秒"); } catch (TesseractException e) { e.printStackTrace(); } System.out.println("result: "); System.out.println(result); } }

2.3 读取pdf的特定位置的数据 2.3.1 手动截取pdf指定矩形区域的材料 需要前端配合做页面,改成自动获取,这样增加文档类型时,需要配置一下。

2.3.2 Python程序获取图片标识区域在整个文档中的矩形坐标

import aircv def matchImg(imgsrc, imgobj, confidence=0.2): """ 图片对比识别imgobj在imgsrc上的相对位置(批量识别统一图片中需要的部分) :param imgsrc: 原始图片路径(str) :param imgobj: 待查找图片路径(模板)(str) :param confidence: 识别度(0


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3