diff --git a/.github/workflows/gen_whl_to_pypi_rapid_layout.yml b/.github/workflows/gen_whl_to_pypi_rapid_layout.yml index ff1b5c4..0fc50c5 100644 --- a/.github/workflows/gen_whl_to_pypi_rapid_layout.yml +++ b/.github/workflows/gen_whl_to_pypi_rapid_layout.yml @@ -6,7 +6,7 @@ on: - v* env: - RESOURCES_URL: https://github.com/RapidAI/RapidStructure/releases/download/v0.0.0/rapid_layout_models.zip + RESOURCES_URL: https://github.com/RapidAI/RapidLayout/releases/download/v0.0.0/rapid_layout_models.zip jobs: UnitTesting: diff --git a/README.md b/README.md index bd2b518..0c9b9ea 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,17 @@ -## Rapid Layout -
+ + +### 简介 - 该部分主要是做文档类图像的版面分析。模型来源:[PaddleOCR 版面分析](https://github.com/PaddlePaddle/PaddleOCR/blob/133d67f27dc8a241d6b2e30a9f047a0fb75bebbe/ppstructure/layout/README_ch.md) - 具体来说,就是分析给定的文档类别图像(论文截图等),定位其中类别和位置,如标题、段落、表格和图片等各个部分。 - 目前支持三种类别的版面分析模型:中文、英文和表格版面分析模型,具体可参见下面表格: @@ -19,64 +24,54 @@ - 模型下载地址为:[百度网盘](https://pan.baidu.com/s/1PI9fksW6F6kQfJhwUkewWg?pwd=p29g) | [Google Drive](https://drive.google.com/drive/folders/1DAPWSN2zGQ-ED_Pz7RaJGTjfkN2-Mvsf?usp=sharing) -#### 安装 +### 安装 由于模型较小,预先将中文版面分析模型(`layout_cdla.onnx`)打包进了whl包内,如果做中文版面分析,可直接安装使用 ```bash $ pip install rapid-layout ``` -#### 使用方式 -1. python脚本运行 - ```python - import cv2 - from rapid_layout import RapidLayout,vis_layout +### 使用方式 +#### python脚本运行 +```python +import cv2 +from rapid_layout import RapidLayout,vis_layout - # model_type类型参见上表。指定不同model_type时,会自动下载相应模型到安装目录下的。 - layout_engine = RapidLayout(box_threshold=0.5, model_type="pp_layout_cdla") +# model_type类型参见上表。指定不同model_type时,会自动下载相应模型到安装目录下的。 +layout_engine = RapidLayout(box_threshold=0.5, model_type="pp_layout_cdla") - img = cv2.imread('test_images/layout.png') +img = cv2.imread('test_images/layout.png') - layout_res, elapse = layout_engine(img) - - ploted_img = vis_layout(img, layout_res) +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) - print(layout_res) - ``` +``` + +#### 终端运行 +- 用法: + ```bash + $ rapid_layout -h + usage: rapid_layout [-h] -img IMG_PATH [-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}] + [--box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}] [-v] -2. 终端运行 - - 用法: - ```bash - $ rapid_layout -h - usage: rapid_layout [-h] -img IMG_PATH [-m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}] - [--box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}] [-v] + options: + -h, --help show this help message and exit + -img IMG_PATH, --img_path IMG_PATH + Path to image for layout. + -m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}, --model_type {pp_layout_cdla,pp_layout_publaynet,pp_layout_table} + Support model type + --box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table} + Box threshold, the range is [0, 1] + -v, --vis Wheter to visualize the layout results. + ``` +- 示例: + ```bash + $ rapid_layout -v -img test_images/layout.png + ``` - options: - -h, --help show this help message and exit - -img IMG_PATH, --img_path IMG_PATH - Path to image for layout. - -m {pp_layout_cdla,pp_layout_publaynet,pp_layout_table}, --model_type {pp_layout_cdla,pp_layout_publaynet,pp_layout_table} - Support model type - --box_threshold {pp_layout_cdla,pp_layout_publaynet,pp_layout_table} - Box threshold, the range is [0, 1] - -v, --vis Wheter to visualize the layout results. - ``` - - 示例: - ```bash - $ rapid_layout -v -img test_images/layout.png - ``` +### 可视化结果 -3. 结果 - - 返回结果 - ```python - # bbox: [左上角x0,左上角y0, 右下角x1, 右下角y1] - # label: 类别 - [ - {'bbox': array([321.4160495, 91.53214898, 562.06141263, 199.85522603]), 'label': 'text'}, - {'bbox': array([58.67292211, 107.29000663, 300.25448676, 199.68142]), 'label': 'table_caption'} - ] - ``` - - 可视化结果 -