深度学习系列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)
相关推荐
qyr678918 分钟前
安全载荷指示器:市场发展现状与未来发展前景趋势分析
大数据·人工智能·安全·自动化·安全载荷指示器
Dawson Zhu24 分钟前
Agent记忆架构深度解析:为什么摘要会丢信息?如何构建“无损优先“的记忆系统
人工智能·语言模型·架构·aigc·agi
迦蓝叶40 分钟前
自建 MaaS 卡住的地方从来不是模型:JAiRouter 开源 AI 网关的四个答案
人工智能·spring boot·开源·架构设计·maas·ai 网关
测试员周周1 小时前
【AI提效】UI自动化页面截图像成功了,业务结果却没有。到底该提缺陷,还是该骂脚本?
人工智能
薛定谔的算法1 小时前
让 AI Agent 直接读飞书群聊帮我干活:一次真实的落地页项目复盘
人工智能
oak隔壁找我1 小时前
一款运行在 (DSH)DeepSeek Harness 中的定时下班提醒插件--下班铃
人工智能
李翌1 小时前
Graphify 实测:13.9 万星的图工具,我拿真项目跑了 34 秒
人工智能
oil欧哟2 小时前
Claude Code 团队是如何做代码审查的
人工智能
skywalk81632 小时前
lightharness第一次大规模开hive任务卡成功
人工智能·hive·agent·deepseek·lightharness
羲云网络2 小时前
GPT Image 2.6 商品多色 SKU 怎么改:从实物参考到颜色、材质验收
图像处理·人工智能·aigc·电商