diff --git a/.github/workflows/gen_whl_to_pypi_rapid_orientation.yml b/.github/workflows/publish_whl.yml similarity index 89% rename from .github/workflows/gen_whl_to_pypi_rapid_orientation.yml rename to .github/workflows/publish_whl.yml index a88c282..dfe69d1 100644 --- a/.github/workflows/gen_whl_to_pypi_rapid_orientation.yml +++ b/.github/workflows/publish_whl.yml @@ -5,7 +5,6 @@ on: tags: - v* - env: RESOURCES_URL: https://github.com/RapidAI/RapidStructure/releases/download/v0.0.0/rapid_orientation_models.zip @@ -31,6 +30,7 @@ jobs: rm rapid_orientation/models/.gitkeep mv $DIR_NAME/*.onnx rapid_orientation/models/ pip install -r requirements.txt + pip install pytest pytest tests/test_orientation.py GenerateWHL_PushPyPi: @@ -49,12 +49,14 @@ jobs: - name: Run setup run: | pip install -r requirements.txt + python -m pip install --upgrade pip + pip install wheel get_pypi_latest_version wget $RESOURCES_URL ZIP_NAME=${RESOURCES_URL##*/} DIR_NAME=${ZIP_NAME%.*} unzip $ZIP_NAME mv $DIR_NAME/*.onnx rapid_orientation/models/ - python setup_orientation.py bdist_wheel ${{ github.ref_name }} + python setup.py bdist_wheel ${{ github.ref_name }} - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@v1.5.0 diff --git a/docs/doc_whl_rapid_orientation.md b/docs/doc_whl_rapid_orientation.md index b676af3..bcb332a 100644 --- a/docs/doc_whl_rapid_orientation.md +++ b/docs/doc_whl_rapid_orientation.md @@ -1,52 +1 @@ -## rapid-orientation -

- - - PyPI - -

- - -### 1. Install package by pypi. -```bash -$ pip install rapid-orientation -``` - -### 2. Run by script. -- RapidOrientation has the default `model_path` value, you can set the different value of `model_path` to use different models, e.g. `orientation_engine = RapidOrientation(model_path='rapid_orientation.onnx')` -- See details, for [README_Layout](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Orientation.md) . -- 📌 `layout.png` source: [link](https://github.com/RapidAI/RapidStructure/blob/main/test_images/layout.png) - -```python -from rapid_orientation import RapidOrientation - -orientation_engine = RapidOrientation() - -with open('test_images/layout.png', 'rb') as f: - img = f.read() -orientation_res, elapse = orientation_engine(img) -print(orientation_res) -``` - -### 3. Run by command line. -- Usage: - ```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 - ``` -- Example: - ```bash - $ rapid_orientation -img layout.png - ``` - -### 4. Result. -```python -# Return str, four types::0 | 90 | 180 | 270 -``` \ No newline at end of file +See [documentation](https://github.com/RapidAI/RapidOrientation) diff --git a/rapid_main.py b/rapid_main.py deleted file mode 100644 index 50a895e..0000000 --- a/rapid_main.py +++ /dev/null @@ -1,105 +0,0 @@ -# -*- encoding: utf-8 -*- -# @Author: SWHL -# @Contact: liekkaskono@163.com -from pathlib import Path - -import cv2 -import numpy as np -from rapid_layout import RapidLayout -from rapid_table import RapidTable -from rapidocr_onnxruntime import RapidOCR - - -def sorted_boxes(dt_boxes): - num_boxes = dt_boxes.shape[0] - sorted_boxes = sorted(dt_boxes, key=lambda x: (x[1], x[0])) - # 按照纵坐标(y)升序,横坐标(x)升序进行排序 - _boxes = list(sorted_boxes) - - for i in range(num_boxes - 1): - for j in range(i, -1, -1): - if ( - abs(_boxes[j + 1][1] - _boxes[j][1]) < 10 - and _boxes[j + 1][0] < _boxes[j][0] - ): - tmp = _boxes[j] - _boxes[j] = _boxes[j + 1] - _boxes[j + 1] = tmp - else: - break - return _boxes - - -def get_boxes(layout_res: list): - r_boxes = [] - # tmp_img = copy.deepcopy(img) - for v in layout_res: - bbox = np.round(v["bbox"]).astype(np.int32) - label = v["label"] - - # start_point = (bbox[0], bbox[1]) - # end_point = (bbox[2], bbox[3]) - - # cv2.rectangle(tmp_img, start_point, end_point, (0, 255, 0), 2) - # box = [bbox[0], bbox[1], bbox[2], bbox[3]] - if label == "table": - r_boxes.append(bbox) - - # r_boxes = sorted_boxes2(r_boxes) - dt_boxes = np.array(r_boxes) - dt_boxes = np.array(sorted_boxes(dt_boxes)) - print(dt_boxes) - return dt_boxes - # print(r_boxes) - # return r_boxes - - -def get_crop_img_list(img, dt_boxes): - # 遍历dt_boxes列表 - crop_imgs = [] - for box in dt_boxes: - x0, y0, x1, y1 = box - # 从原始图像中截取指定位置的图像 - cropped_img = img[y0:y1, x0:x1] - crop_imgs.append(cropped_img) - - return crop_imgs - - -def test_input(): - layout_engine = RapidLayout() - - cur_dir = Path(__file__).resolve().parent - test_file_dir = cur_dir / "tests" / "test_files" - img_path = test_file_dir / "layout.png" - - img = cv2.imread(str(img_path)) - # layout_res, elapse = layout_engine(img) - layout_res, elapse = layout_engine(img) - print(layout_res) - dt_boxes = get_boxes(layout_res) - img_crop_list = get_crop_img_list(img, dt_boxes) - # 打印截取的图像列表 - # for i, cropped_img in enumerate(img_crop_list): - # cv2.imshow(f"Cropped Image {i + 1}", cropped_img) - - table_engine = RapidTable() - ocr_engine = RapidOCR() - - # img_path = "tests/test_files/table.jpg" - table_html = [] - for i, cropped_img in enumerate(img_crop_list): - ocr_result, _ = ocr_engine(cropped_img) - table_html_str, _, _ = table_engine(cropped_img, ocr_result) - table_html.append(table_html_str) # i, - - print(table_html) - - # cv2.waitKey(0) - # cv2.destroyAllWindows() - - # assert len(layout_res) == 13 - - -if __name__ == "__main__": - test_input() diff --git a/requirements.txt b/requirements.txt index 8504325..924990c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,5 @@ numpy>=1.21.6,<2.0.0 opencv_python>=4.6.0.66 -setuptools>=61.2.0 PyYAML -pytest==8.1.1 -pip>=24.0 onnxruntime -wheel -get_pypi_latest_version -Pillow -tqdm -requests \ No newline at end of file +Pillow \ No newline at end of file diff --git a/setup_orientation.py b/setup.py similarity index 73% rename from setup_orientation.py rename to setup.py index 2d0ec69..42011e3 100644 --- a/setup_orientation.py +++ b/setup.py @@ -3,11 +3,21 @@ # @Contact: liekkaskono@163.com import sys from pathlib import Path +from typing import List import setuptools from get_pypi_latest_version import GetPyPiLatestVersion +def read_txt(txt_path: str) -> List: + if not isinstance(txt_path, str): + txt_path = str(txt_path) + + with open(txt_path, "r", encoding="utf-8") as f: + data = list(map(lambda x: x.rstrip("\n"), f)) + return data + + def get_readme(): root_dir = Path(__file__).resolve().parent readme_path = str(root_dir / "docs" / "doc_whl_rapid_orientation.md") @@ -32,22 +42,14 @@ def get_readme(): name=MODULE_NAME, version=VERSION_NUM, platforms="Any", - long_description=get_readme(), - long_description_content_type="text/markdown", description="Tools for classifying the direction of images containing text based ONNXRuntime.", author="SWHL", author_email="liekkaskono@163.com", - url="https://github.com/RapidAI/RapidStructure", + url="https://github.com/RapidAI/RapidOrientation", license="Apache-2.0", include_package_data=True, - install_requires=[ - "onnxruntime>=1.7.0", - "PyYAML>=6.0", - "opencv_python>=4.5.1.48", - "numpy>=1.21.6", - "Pillow", - ], - packages=[MODULE_NAME, f"{MODULE_NAME}.models"], + install_requires=read_txt("requirements.txt"), + packages=[MODULE_NAME, f"{MODULE_NAME}.models", f"{MODULE_NAME}.utils"], package_data={"": ["*.onnx", "*.yaml"]}, keywords=["ppstructure,layout,rapidocr,rapid_orientation"], classifiers=[ @@ -58,8 +60,6 @@ def get_readme(): "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", ], - python_requires=">=3.6,<3.12", - entry_points={ - "console_scripts": [f"{MODULE_NAME}={MODULE_NAME}.{MODULE_NAME}:main"] - }, + python_requires=">=3.6,<3.13", + entry_points={"console_scripts": [f"{MODULE_NAME}={MODULE_NAME}.main:main"]}, )