feat(rapidocr_paddle): support to char rec and bump to v1.4.0

This commit is contained in:
SWHL committed 2024-11-21 10:00:12 +08:00
1 parent 33ba2a9a65
commit 3e13f481a1
9 files changed
+436 -90

No files matched your search

-2
View File
@@ -2,7 +2,6 @@
# @Author: SWHL
# @Contact: liekkaskono@163.com
import logging
import platform
import sys
from pathlib import Path
from typing import List
@@ -22,7 +21,6 @@ engine = RapidOCR()
tests_dir = root_dir / "tests" / "test_files"
img_path = tests_dir / "ch_en_num.jpg"
package_name = "rapidocr_onnxruntime"
cur_platform = platform.system()
def test_long_img():
+31 -57
View File
@@ -3,6 +3,7 @@
# @Contact: liekkaskono@163.com
import sys
from pathlib import Path
from typing import List
import cv2
import numpy as np
@@ -12,7 +13,7 @@ root_dir = Path(__file__).resolve().parent.parent
sys.path.append(str(root_dir))
from rapidocr_paddle import LoadImageError, RapidOCR
from tests.base_module import BaseModule, download_file
from tests.base_module import download_file
engine = RapidOCR()
tests_dir = root_dir / "tests" / "test_files"
@@ -199,61 +200,34 @@ def test_input_three_ndim_one_channel():
result, _ = engine(img)
assert result[0][1] == "正品促销"
assert len(result) == 17
assert len(result) >= 17
def test_det():
module_name = "ch_ppocr_det"
class_name = "TextDetector"
base = BaseModule(package_name)
TextDetector = base.init_module(module_name, class_name)
yaml_path = base.package_dir / module_name / "config.yaml"
config = base.read_yaml(str(yaml_path))
config["model_path"] = str(base.package_dir / config["model_path"])
text_det = TextDetector(config)
img_path = base.tests_dir / "test_files" / "text_det.jpg"
img = cv2.imread(str(img_path))
dt_boxes, elapse = text_det(img)
assert dt_boxes.shape == (18, 4, 2)
def test_cls():
module_name = "ch_ppocr_cls"
class_name = "TextClassifier"
base = BaseModule(package_name=package_name)
TextClassifier = base.init_module(module_name, class_name)
yaml_path = base.package_dir / module_name / "config.yaml"
config = base.read_yaml(str(yaml_path))
config["model_path"] = str(base.package_dir / config["model_path"])
text_cls = TextClassifier(config)
img_path = base.tests_dir / "test_files" / "text_cls.jpg"
img = cv2.imread(str(img_path))
result = text_cls([img])
assert result[1][0][0] == "180"
def test_rec():
module_name = "ch_ppocr_rec"
class_name = "TextRecognizer"
base = BaseModule(package_name)
TextRecognizer = base.init_module(module_name, class_name)
yaml_path = base.package_dir / module_name / "config.yaml"
config = base.read_yaml(str(yaml_path))
config["model_path"] = str(base.package_dir / config["model_path"])
text_rec = TextRecognizer(config)
img_path = base.tests_dir / "test_files" / "text_rec.jpg"
img = cv2.imread(str(img_path))
rec_res, elapse = text_rec(img)
assert rec_res[0][0] == "韩国小馆"
@pytest.mark.parametrize(
"img_name,words",
[
(
"black_font_color_transparent.png",
["我", "是", "中", "国", "人"],
),
(
"text_vertical_words.png",
[
"已",
"取",
"之",
"時",
"不",
"參",
"一",
"人",
"见",
"而",
], # rapidocr_onnxruntime: 見, rapidocr_paddle: 见
),
],
)
def test_word_ocr(img_name: str, words: List[str]):
img_path = tests_dir / img_name
result, _ = engine(img_path, return_word_box=True)
assert result[0][4] == words