-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
59 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,9 @@ name: Push rapidocr_orientation to pypi | |
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'rapid_orientation/**' | ||
- 'docs/doc_whl_rapid_orientation.md' | ||
- 'setup_orientation.py' | ||
- '.github/workflows/gen_whl_to_pypi_rapid_orientation.yml' | ||
- 'tests/test_orientation.py' | ||
tags: | ||
- v* | ||
|
||
|
||
env: | ||
RESOURCES_URL: https://github.com/RapidAI/RapidStructure/releases/download/v0.0.0/rapid_orientation_models.zip | ||
|
@@ -59,14 +55,7 @@ jobs: | |
DIR_NAME=${ZIP_NAME%.*} | ||
unzip $ZIP_NAME | ||
mv $DIR_NAME/*.onnx rapid_orientation/models/ | ||
python setup_orientation.py bdist_wheel ${{ github.event.head_commit.message }} | ||
# - name: Publish distribution 📦 to Test PyPI | ||
# uses: pypa/[email protected] | ||
# with: | ||
# password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
# repository_url: https://test.pypi.org/legacy/ | ||
# packages_dir: dist/ | ||
python setup_orientation.py bdist_wheel ${{ github.ref_name }} | ||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,68 @@ | ||
<div align="center"> | ||
<div align="center"> | ||
<h1><b>📃 Rapid Structure</b></h1> | ||
<h1><b>Rapid Orientation</b></h1> | ||
</div> | ||
|
||
<a href="https://swhl-rapidstructuredemo.hf.space" target="_blank"><img src="https://img.shields.io/badge/%F0%9F%A4%97-Online Demo-blue"></a> | ||
<a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.12-aff.svg"></a> | ||
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a> | ||
<a href="https://pepy.tech/project/rapid-layout"><img src="https://static.pepy.tech/personalized-badge/rapid-layout?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-layout"></a> | ||
<a href="https://pepy.tech/project/rapid-orientation"><img src="https://static.pepy.tech/personalized-badge/rapid-orientation?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-orientation"></a> | ||
<a href="https://pepy.tech/project/rapid-table"><img src="https://static.pepy.tech/personalized-badge/rapid-table?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-table"></a> | ||
<a href="https://semver.org/"><img alt="SemVer2.0" src="https://img.shields.io/badge/SemVer-2.0-brightgreen"></a> | ||
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a> | ||
<a href="https://pypi.org/project/rapid-orientation/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-orientation"></a> | ||
<a href="https://pepy.tech/project/rapid-orientation"><img src="https://static.pepy.tech/personalized-badge/rapid-orientation?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a> | ||
|
||
</div> | ||
|
||
### 简介 | ||
### 简介和说明 | ||
|
||
该部分的功能主要针对文档类图像,包括文档图像分类、版面分析和表格识别。 | ||
该部分主要是做含文字图像方向分类模型。模型来源:[PaddleClas 含文字图像方向分类模型](https://github.com/PaddlePaddle/PaddleClas/blob/177e4be74639c0960efeae2c5166d3226c9a02eb/docs/zh_CN/models/PULC/PULC_text_image_orientation.md) | ||
|
||
可配套使用项目:[RapidOCR](https://github.com/RapidAI/RapidOCR) | ||
| 模型类型 | 模型名称 | 模型大小 | 支持种类 | | ||
|:---:|:---:|:---:|:---:| | ||
| 四方向分类 | `rapid_orientation.onnx` | 6.5M | `0 90 180 270`| | ||
|
||
相关模型托管:[Hugging Face Models](https://huggingface.co/SWHL/RapidStructure) | ||
### 安装 | ||
|
||
### [文档方向分类](./docs/README_Orientation.md) | ||
由于模型较小,已经将分类模型(`rapid_orientation.onnx`)打包进了whl包内: | ||
|
||
### [版面分析](https://github.com/RapidAI/RapidLayout) | ||
```bash | ||
pip install rapid-orientation | ||
``` | ||
|
||
### [表格识别](https://github.com/RapidAI/RapidTable) | ||
### 脚本运行 | ||
|
||
更多表格识别:[TableStructureRec](https://github.com/RapidAI/TableStructureRec) | ||
```python | ||
import cv2 | ||
|
||
### 🔥🔥[版面还原](https://github.com/RapidAI/RapidDoc) | ||
from rapid_orientation import RapidOrientation | ||
|
||
### 整体流程 | ||
orientation_engine = RapidOrientation() | ||
img = cv2.imread("tests/test_files/img_rot180_demo.jpg") | ||
cls_result, _ = orientation_engine(img) | ||
print(cls_result) | ||
``` | ||
|
||
### 终端运行 | ||
|
||
用法: | ||
|
||
```bash | ||
$ rapid_orientation -h | ||
usage: rapid_orientation [-h] -img IMG_PATH [-m MODEL_PATH] | ||
|
||
optional arguments: | ||
-h, --help show this help message and exit | ||
-img IMG_PATH, --img_path IMG_PATH | ||
Path to image for layout. | ||
-m MODEL_PATH, --model_path MODEL_PATH | ||
The model path used for inference. | ||
``` | ||
|
||
示例: | ||
|
||
```bash | ||
rapid_orientation -img test_images/layout.png | ||
``` | ||
|
||
结果 | ||
|
||
```mermaid | ||
flowchart TD | ||
A[/文档图像/] --> B([文档方向分类 rapid_orientation]) --> C([版面分析 rapid_layout]) | ||
C --> D([表格识别 rapid_table]) & E([公式识别 rapid_latex_ocr]) & F([文字识别 rapidocr_onnxruntime]) --> G([版面还原 rapid_layout_recover]) | ||
G --> H[/结构化输出/] | ||
```python | ||
# 返回结果为str类型,有四类:0 | 90 | 180 | 270 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,11 @@ | ||
# -*- encoding: utf-8 -*- | ||
# @Author: SWHL | ||
# @Contact: [email protected] | ||
from pathlib import Path | ||
|
||
import cv2 | ||
|
||
from rapid_layout import RapidLayout, VisLayout | ||
from rapid_orientation import RapidOrientation | ||
from rapid_table import RapidTable, VisTable | ||
|
||
|
||
def vis_table(table_res): | ||
style_res = """<style>td {border-left: 1px solid;border-bottom:1px solid;} | ||
table, th {border-top:1px solid;font-size: 10px; | ||
border-collapse: collapse;border-right: 1px solid;} | ||
</style>""" | ||
prefix_table, suffix_table = table_res.split("<body>") | ||
new_table_res = f"{prefix_table}{style_res}<body>{suffix_table}" | ||
|
||
draw_img_save = Path("./inference_results/") | ||
if not draw_img_save.exists(): | ||
draw_img_save.mkdir(parents=True, exist_ok=True) | ||
|
||
html_path = str(draw_img_save / "table_result.html") | ||
with open(html_path, "w", encoding="utf-8") as f: | ||
f.write(new_table_res) | ||
print(f"The infer result has saved in {html_path}") | ||
|
||
|
||
def demo_layout(): | ||
layout_engine = RapidLayout(box_threshold=0.5, model_type="pp_layout_cdla") | ||
|
||
img_path = "tests/test_files/layout.png" | ||
img = cv2.imread(img_path) | ||
|
||
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) | ||
|
||
|
||
def demo_table(): | ||
from rapidocr_onnxruntime import RapidOCR, VisRes | ||
|
||
ocr_engine = RapidOCR() | ||
vis_ocr = VisRes() | ||
table_engine = RapidTable() | ||
viser = VisTable() | ||
|
||
img_path = "1.png" | ||
ocr_result, _ = ocr_engine(img_path) | ||
|
||
table_html_str, table_cell_bboxes, _ = table_engine(img_path, ocr_result) | ||
|
||
boxes, txts, scores = list(zip(*ocr_result)) | ||
|
||
save_dir = Path("./inference_results/") | ||
if not save_dir.exists(): | ||
save_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
save_html_path = save_dir / f"{Path(img_path).stem}.html" | ||
save_drawed_path = save_dir / f"vis_{Path(img_path).name}" | ||
vis_imged = viser( | ||
img_path, table_html_str, save_html_path, table_cell_bboxes, save_drawed_path | ||
) | ||
res = vis_ocr(vis_imged, boxes) | ||
cv2.imwrite("only_vis_det.png", res) | ||
print(table_html_str) | ||
|
||
|
||
def demo_orientation(): | ||
orientation_engine = RapidOrientation() | ||
img = cv2.imread("tests/test_files/img_rot180_demo.jpg") | ||
cls_result, _ = orientation_engine(img) | ||
print(cls_result) | ||
|
||
|
||
if __name__ == "__main__": | ||
demo_layout() | ||
# demo_table() | ||
# demo_orientation() | ||
orientation_engine = RapidOrientation() | ||
img = cv2.imread("tests/test_files/img_rot180_demo.jpg") | ||
cls_result, _ = orientation_engine(img) | ||
print(cls_result) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# -*- encoding: utf-8 -*- | ||
# @Author: SWHL | ||
# @Contact: [email protected] | ||
from .rapid_orientation import RapidOrientation | ||
from .main import RapidOrientation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters