Skip to content

Commit

Permalink
Fixed issue #122
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Sep 20, 2023
1 parent 9527f71 commit 6d53213
Show file tree
Hide file tree
Showing 19 changed files with 410 additions and 434 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/gen_whl_to_pypi_rapidocr_ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
cp $DIR_NAME/resources/models/*.onnx python/rapidocr_onnxruntime/models/
cp $DIR_NAME/resources/models/*.onnx python/rapidocr_openvino/models/
cd python
pip install -r requirements.txt
pip install -r requirements_ort.txt
pip install pytest wheel get_pypi_latest_version
cd tests
wget $TWO_DIM_IMAGE -O two_dim_image.npy
mv two_dim_image.npy test_files/
Expand Down Expand Up @@ -78,25 +79,18 @@ jobs:
- name: Run setup_onnxruntime.py
run: |
cd python
pip install -r requirements.txt
pip install setuptools get_pypi_latest_version wheel
mkdir rapidocr_onnxruntime_t
mv rapidocr_onnxruntime rapidocr_onnxruntime_t
mv rapidocr_onnxruntime_t rapidocr_onnxruntime
cd rapidocr_onnxruntime
echo "from .rapidocr_onnxruntime.rapid_ocr_api import RapidOCR" > __init__.py
echo "from .rapidocr_onnxruntime.main import RapidOCR" > __init__.py
cd ..
python -m pip install --upgrade pip
python setup_onnxruntime.py bdist_wheel ${{ github.event.head_commit.message }}
mv dist ../
# - name: Publish distribution 📦 to Test PyPI
# uses: pypa/gh-action-pypi-publish@v1.5.0
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
# packages_dir: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@v1.5.0
with:
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/gen_whl_to_pypi_rapidocr_vino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
cp $DIR_NAME/resources/models/*.onnx python/rapidocr_onnxruntime/models/
cp $DIR_NAME/resources/models/*.onnx python/rapidocr_openvino/models/
cd python
pip install -r requirements.txt
pip install -r requirements_vino.txt
pip install pytest wheel get_pypi_latest_version
cd tests
wget $TWO_DIM_IMAGE -O two_dim_image.npy
mv two_dim_image.npy test_files/
Expand Down Expand Up @@ -78,25 +79,18 @@ jobs:
- name: Run setup_openvino.py
run: |
cd python
pip install -r requirements.txt
pip install setuptools get_pypi_latest_version wheel
mkdir rapidocr_openvino_t
mv rapidocr_openvino rapidocr_openvino_t
mv rapidocr_openvino_t rapidocr_openvino
cd rapidocr_openvino
echo "from .rapidocr_openvino.rapid_ocr_api import RapidOCR" > __init__.py
echo "from .rapidocr_openvino.main import RapidOCR" > __init__.py
cd ..
python -m pip install --upgrade pip
python setup_openvino.py bdist_wheel ${{ github.event.head_commit.message }}
mv dist ../
# - name: Publish distribution 📦 to Test PyPI
# uses: pypa/gh-action-pypi-publish@v1.5.0
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
# packages_dir: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@v1.5.0
with:
Expand Down
112 changes: 2 additions & 110 deletions docs/doc_whl_rapidocr_ort.md
Original file line number Diff line number Diff line change
@@ -1,116 +1,8 @@
## rapidocr-onnxruntime Package
## rapidocr-onnxruntime
<p>
<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/rapidocr_onnxruntime"><img src="https://static.pepy.tech/personalized-badge/rapidocr_onnxruntime?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads%20Ort"></a>
</p>

### 1. Install package by pypi.
```bash
$ pip install rapidocr-onnxruntime
```

### 2. Use.
- Run by script.
```python
import cv2
from rapidocr_onnxruntime import RapidOCR

rapid_ocr = RapidOCR()

img_path = 'tests/test_files/ch_en_num.jpg'

# Support:Union[str, np.ndarray, bytes, Path]
# str
result, elapse = rapid_ocr(img_path)

# np.ndarray
img = cv2.imread('tests/test_files/ch_en_num.jpg')
result, elapse = rapid_ocr(img)

# bytes
with open(img_path, 'rb') as f:
result, elapse = rapid_ocr(f.read())

# Path
result, elapse = rapid_ocr(Path(img_path))
print(result)

# result: [[dt_boxes], txt, score]
# e.g.:[[left-top, right-top, right-down, left-top], '小明', '0.99']

# elapse: [det_elapse, cls_elapse, rec_elapse]
# all_elapse = det_elapse + cls_elapse + rec_elapse

# If without valid texts, result: (None, None )
```

- Run by command line.
```bash
$ rapidocr_onnxruntime -h
usage: rapidocr_onnxruntime [-h] -img IMG_PATH [-p] [--text_score TEXT_SCORE]
[--use_angle_cls USE_ANGLE_CLS]
[--use_text_det USE_TEXT_DET]
[--print_verbose PRINT_VERBOSE]
[--min_height MIN_HEIGHT]
[--width_height_ratio WIDTH_HEIGHT_RATIO]
[--det_use_cuda DET_USE_CUDA]
[--det_model_path DET_MODEL_PATH]
[--det_limit_side_len DET_LIMIT_SIDE_LEN]
[--det_limit_type {max,min}]
[--det_thresh DET_THRESH]
[--det_box_thresh DET_BOX_THRESH]
[--det_unclip_ratio DET_UNCLIP_RATIO]
[--det_use_dilation DET_USE_DILATION]
[--det_score_mode {slow,fast}]
[--cls_use_cuda CLS_USE_CUDA]
[--cls_model_path CLS_MODEL_PATH]
[--cls_image_shape CLS_IMAGE_SHAPE]
[--cls_label_list CLS_LABEL_LIST]
[--cls_batch_num CLS_BATCH_NUM]
[--cls_thresh CLS_THRESH]
[--rec_use_cuda REC_USE_CUDA]
[--rec_model_path REC_MODEL_PATH]
[--rec_img_shape REC_IMAGE_SHAPE]
[--rec_batch_num REC_BATCH_NUM]

optional arguments:
-h, --help show this help message and exit
-img IMG_PATH, --img_path IMG_PATH MUST
-p, --print_cost

Global:
--text_score TEXT_SCORE
--use_angle_cls USE_ANGLE_CLS
--use_text_det USE_TEXT_DET
--print_verbose PRINT_VERBOSE
--min_height MIN_HEIGHT
--width_height_ratio WIDTH_HEIGHT_RATIO

Det:
--det_use_cuda DET_USE_CUDA
--det_model_path DET_MODEL_PATH
--det_limit_side_len DET_LIMIT_SIDE_LEN
--det_limit_type {max,min}
--det_thresh DET_THRESH
--det_box_thresh DET_BOX_THRESH
--det_unclip_ratio DET_UNCLIP_RATIO
--det_use_dilation DET_USE_DILATION
--det_score_mode {slow,fast}

Cls:
--cls_use_cuda CLS_USE_CUDA
--cls_model_path CLS_MODEL_PATH
--cls_image_shape CLS_IMAGE_SHAPE
--cls_label_list CLS_LABEL_LIST
--cls_batch_num CLS_BATCH_NUM
--cls_thresh CLS_THRESH

Rec:
--rec_use_cuda REC_USE_CUDA
--rec_model_path REC_MODEL_PATH
--rec_img_shape REC_IMAGE_SHAPE
--rec_batch_num REC_BATCH_NUM

$ rapidocr_onnxruntime -img tests/test_files/ch_en_num.jpg
```
### See [Documentation](https://rapidai.github.io/RapidOCRDocs/docs/install_usage/rapidocr/rapidocr_onnxruntime/)
107 changes: 2 additions & 105 deletions docs/doc_whl_rapidocr_vino.md
Original file line number Diff line number Diff line change
@@ -1,111 +1,8 @@
## rapidocr-openvino Package
## rapidocr-openvino
<p>
<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/rapidocr_openvino"><img src="https://static.pepy.tech/personalized-badge/rapidocr_openvino?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads%20Vino"></a>
</p>

### 1. Install package by pypi.
```shell
$ pip install rapidocr-openvino
```


### 2. Use.
- Run by script.
```python
import cv2
from rapidocr_openvino import RapidOCR

rapid_ocr = RapidOCR()

img_path = 'tests/test_files/ch_en_num.jpg'

# Support:Union[str, np.ndarray, bytes, Path]
# str
result, elapse = rapid_ocr(img_path)

# np.ndarray
img = cv2.imread('tests/test_files/ch_en_num.jpg')
result, elapse = rapid_ocr(img)

# bytes
with open(img_path, 'rb') as f:
result, elapse = rapid_ocr(f.read())

# Path
result, elapse = rapid_ocr(Path(img_path))
print(result)

# result: [[dt_boxes], txt, score]
# e.g.:[[left-top, right-top, right-down, left-top], '小明', '0.99']

# elapse: [det_elapse, cls_elapse, rec_elapse]
# all_elapse = det_elapse + cls_elapse + rec_elapse

# If without valid texts, result: (None, None )
```

- Run by command line.
```bash
$ rapidocr_openvino -h
usage: rapidocr_openvino [-h] -img IMG_PATH [-p] [--text_score TEXT_SCORE]
[--use_angle_cls USE_ANGLE_CLS]
[--use_text_det USE_TEXT_DET]
[--print_verbose PRINT_VERBOSE]
[--min_height MIN_HEIGHT]
[--width_height_ratio WIDTH_HEIGHT_RATIO]
[--det_model_path DET_MODEL_PATH]
[--det_limit_side_len DET_LIMIT_SIDE_LEN]
[--det_limit_type {max,min}]
[--det_thresh DET_THRESH]
[--det_box_thresh DET_BOX_THRESH]
[--det_unclip_ratio DET_UNCLIP_RATIO]
[--det_use_dilation DET_USE_DILATION]
[--det_score_mode {slow,fast}]
[--cls_model_path CLS_MODEL_PATH]
[--cls_image_shape CLS_IMAGE_SHAPE]
[--cls_label_list CLS_LABEL_LIST]
[--cls_batch_num CLS_BATCH_NUM]
[--cls_thresh CLS_THRESH]
[--rec_model_path REC_MODEL_PATH]
[--rec_img_shape REC_IMAGE_SHAPE]
[--rec_batch_num REC_BATCH_NUM]

optional arguments:
-h, --help show this help message and exit
-img IMG_PATH, --img_path IMG_PATH
-p, --print_cost

Global:
--text_score TEXT_SCORE
--use_angle_cls USE_ANGLE_CLS
--use_text_det USE_TEXT_DET
--print_verbose PRINT_VERBOSE
--min_height MIN_HEIGHT
--width_height_ratio WIDTH_HEIGHT_RATIO

Det:
--det_model_path DET_MODEL_PATH
--det_limit_side_len DET_LIMIT_SIDE_LEN
--det_limit_type {max,min}
--det_thresh DET_THRESH
--det_box_thresh DET_BOX_THRESH
--det_unclip_ratio DET_UNCLIP_RATIO
--det_use_dilation DET_USE_DILATION
--det_score_mode {slow,fast}

Cls:
--cls_model_path CLS_MODEL_PATH
--cls_image_shape CLS_IMAGE_SHAPE
--cls_label_list CLS_LABEL_LIST
--cls_batch_num CLS_BATCH_NUM
--cls_thresh CLS_THRESH

Rec:
--rec_model_path REC_MODEL_PATH
--rec_img_shape REC_IMAGE_SHAPE
--rec_batch_num REC_BATCH_NUM

$ rapidocr_openvino -img tests/test_files/ch_en_num.jpg
```
### See [Documentation](https://rapidai.github.io/RapidOCRDocs/docs/install_usage/rapidocr/rapidocr_openvino/)
8 changes: 3 additions & 5 deletions python/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ def visualize(image_path, result, font_path="resources/fonts/FZYTK.TTF"):
if __name__ == "__main__":
rapid_ocr = RapidOCR()

image_path = "res.png"
# with open(image_path, "rb") as f:
# img = f.read()
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
image_path = "tests/test_files/ch_en_num.jpg"
with open(image_path, "rb") as f:
img = f.read()
result, elapse_list = rapid_ocr(img)
print(result)
print(elapse_list)
Expand Down
2 changes: 1 addition & 1 deletion python/rapidocr_onnxruntime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: liekkaskono@163.com
from .rapid_ocr_api import RapidOCR
from .main import RapidOCR
from .utils import LoadImageError
5 changes: 3 additions & 2 deletions python/rapidocr_onnxruntime/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Global:
text_score: 0.5
use_angle_cls: true
use_text_det: true
use_det: true
use_cls: true
use_rec: true
print_verbose: false
min_height: 30
width_height_ratio: 8
Expand Down
Loading

0 comments on commit 6d53213

Please sign in to comment.