Fix issue 232 (#235)

* fix(rapidocr_onnxruntime): Fixed padding_h variable before assignment

* feat(rapidocr_onnxruntime): Add resize function

* feat(rapidocr_onnxruntime): Add limit of max_side_len and min_side_len

* tests: Add __init__
This commit is contained in:
SWHL authored and GitHub committed 2024-10-17 22:24:31 +08:00
1 parent b2fd006ee6
commit fd520ffdad
10 files changed
+206 -14

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: liekkaskono@163.com
+23
View File
@@ -4,8 +4,11 @@
import importlib
import sys
from pathlib import Path
from typing import Union
import requests
import yaml
from tqdm import tqdm
class BaseModule:
@@ -30,3 +33,23 @@ class BaseModule:
with open(yaml_path, "rb") as f:
data = yaml.load(f, Loader=yaml.Loader)
return data
def download_file(url: str, save_path: Union[str, Path]):
response = requests.get(url, stream=True, timeout=60)
status_code = response.status_code
if status_code != 200:
raise DownloadModelError("Something went wrong while downloading models")
total_size_in_bytes = int(response.headers.get("content-length", 1))
block_size = 1024 # 1 Kibibyte
with tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True) as pb:
with open(save_path, "wb") as file:
for data in response.iter_content(block_size):
pb.update(len(data))
file.write(data)
class DownloadModelError(Exception):
pass
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

+15
View File
@@ -13,6 +13,7 @@ root_dir = Path(__file__).resolve().parent.parent
sys.path.append(str(root_dir))
from rapidocr_onnxruntime import LoadImageError, RapidOCR
from tests.base_module import download_file
engine = RapidOCR()
tests_dir = root_dir / "tests" / "test_files"
@@ -20,6 +21,16 @@ img_path = tests_dir / "ch_en_num.jpg"
package_name = "rapidocr_onnxruntime"
def test_long_img():
img_url = "https://github.com/RapidAI/RapidOCR/releases/download/v1.1.0/long.jpeg"
img_path = tests_dir / "long.jpeg"
download_file(img_url, save_path=img_path)
result, _ = engine(img_path)
assert result is not None
assert len(result) == 55
img_path.unlink()
def test_ort_cuda_warning(caplog):
engine = RapidOCR(det_use_cuda=True)
caplog.set_level(logging.WARNING)
@@ -111,6 +122,7 @@ def test_cls_rec():
img_path = tests_dir / "text_cls.jpg"
result, _ = engine(img_path, use_det=False, use_cls=True, use_rec=True)
assert result is not None
assert len(result) == 1
assert result[0][0] == "韩国小馆"
@@ -119,6 +131,7 @@ def test_det_cls_rec():
img = cv2.imread(str(img_path))
result, _ = engine(img)
assert result is not None
assert result[0][1] == "正品促销"
assert len(result) == 18
@@ -193,6 +206,7 @@ def test_input_three_ndim_two_channel():
image_array = np.load(str(img_npy))
result, _ = engine(image_array)
assert result is not None
assert len(result) == 1
assert result[0][1] == "TREND PLOT REPORT"
@@ -205,5 +219,6 @@ def test_input_three_ndim_one_channel():
result, _ = engine(img)
assert result is not None
assert result[0][1] == "正品促销"
assert len(result) == 17