深度学习系列73:使用rapidStructure进行版面分析

1. 概述

项目地址https://github.com/RapidAI/RapidStructure?tab=readme-ov-file

2. 文档方向分类示例

安装$ pip install rapid-orientation

import cv2
from rapid_orientation import RapidOrientation
orientation_engine = RapidOrientation()
img = cv2.imread('test_images/layout.png')
orientation_res, elapse = orientation_engine(img)
print(orientation_res)
# 返回结果为str类型,有四类:0 | 90 | 180 | 270

3. 版面分析RapidLayout

安装$ pip install rapid-layout

import cv2
from rapid_layout import RapidLayout, VisLayout

# model_type类型参见上表。指定不同model_type时,会自动下载相应模型到安装目录下的。
layout_engine = RapidLayout(conf_thres=0.5, model_type="pp_layout_cdla")

img = cv2.imread('test_images/layout.png')

boxes, scores, class_names, elapse = layout_engine(img)
ploted_img = VisLayout.draw_detections(img, boxes, scores, class_names)
if ploted_img is not None:
    cv2.imwrite("layout_res.png", ploted_img)

4. 文字识别和表格识别rapid_table

from rapid_table import RapidTable, VisTable

# RapidTable类提供model_path参数,可以自行指定上述2个模型,默认是en_ppstructure_mobile_v2_SLANet.onnx
# table_engine = RapidTable(model_path='ch_ppstructure_mobile_v2_SLANet.onnx')
table_engine = RapidTable()
ocr_engine = RapidOCR()
viser = VisTable()

img_path = 'test_images/table.jpg'

ocr_result, _ = ocr_engine(img_path)
table_html_str, table_cell_bboxes, elapse = table_engine(img_path, ocr_result)

5. latex识别rapidLaTexOCR

from rapid_latex_ocr import LatexOCR
model = LatexOCR()
img_path = "tests/test_files/6.png"
with open(img_path, "rb") as f:
    data = f.read()
res, elapse = model(data)

6. 整合版:RapidOCRPDF

# 基于CPU 依赖rapidocr_onnxruntime
pip install rapidocr_pdf[onnxruntime]
# 基于CPU 依赖rapidocr_openvino 更快
pip install rapidocr_pdf[openvino]
# 基于GPU 依赖rapidocr_paddle
pip install rapidocr_pdf[paddle]

使用:

from rapidocr_pdf import PDFExtracter
pdf_extracter = PDFExtracter()
pdf_path = 'tests/test_files/direct_and_image.pdf'
texts = pdf_extracter(pdf_path, force_ocr=False)
print(texts)
相关推荐
水花花花花花几秒前
matlab处理函数3
人工智能
奥利给少年11 分钟前
Machine Learning: A Probabilistic Perspective 机器学习:概率视角 PDF免费分享
人工智能·机器学习·开源
有梦想的程序星空13 分钟前
【四范式】浅谈NLP发展的四个范式
人工智能·gpt·自然语言处理
火山引擎边缘云44 分钟前
探索端智能,加速大模型应用,火山引擎边缘智能 x 扣子技术沙龙等你来
人工智能·机器人·火山引擎
张琪杭1 小时前
深度学习-目标检测(一)-R-CNN
人工智能·深度学习·算法·目标检测·cnn
为为-180-3121-14551 小时前
基于多技术融合在生态系统服务构建生态安全格局中的实践技术应用
大数据·人工智能·安全
再不会python就不礼貌了1 小时前
一步步教你利用大模型开发个性化AI应用,告别‘人工智障’!
人工智能·学习·算法·oracle·llama
AI科技圈.1 小时前
用最新方案为数据密集型AI供能:将服务器农场沉入旧金山湾
大数据·服务器·人工智能
繁依Fanyi1 小时前
SpringBoot + Vue + ElementUI 实现 el-table 分页功能详解
java·开发语言·人工智能·python·算法
鑫宝Code1 小时前
【机器学习】迁移学习概论
人工智能·机器学习·迁移学习