📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Support transparent white font image rec in rapidocr_onnxruntime
SWHL55bb974b5d93
diff --git a/python/demo.py b/python/demo.pyindex 5e5d6f7..cd5cf16 100644--- a/python/demo.py+++ b/python/demo.py@@ -12,7 +12,7 @@ from rapidocr_onnxruntime import RapidOCR, VisResengine = RapidOCR()vis = VisRes()-image_path = "tests/test_files/test_without_det.jpg"+image_path = "tests/test_files/black_font_color_transparent.png"with open(image_path, "rb") as f:img = f.read()diff --git a/python/rapidocr_onnxruntime/utils.py b/python/rapidocr_onnxruntime/utils.pyindex 778066d..181dd91 100644--- a/python/rapidocr_onnxruntime/utils.py+++ b/python/rapidocr_onnxruntime/utils.py@@ -208,7 +208,12 @@ class LoadImage:not_a = cv2.cvtColor(not_a, cv2.COLOR_GRAY2BGR)new_img = cv2.bitwise_and(new_img, new_img, mask=a)- new_img = cv2.add(new_img, not_a)++ mean_color = np.mean(new_img)+ if mean_color <= 0.0:+ new_img = cv2.add(new_img, not_a)+ else:+ new_img = cv2.bitwise_not(new_img)return new_img@staticmethoddiff --git a/python/tests/test_files/black_font_color_transparent.png b/python/tests/test_files/black_font_color_transparent.pngnew file mode 100644index 0000000..dfd20a1Binary files /dev/null and b/python/tests/test_files/black_font_color_transparent.png differdiff --git a/python/tests/test_files/white_font_color_transparent.png b/python/tests/test_files/white_font_color_transparent.pngnew file mode 100644index 0000000..9f9f095Binary files /dev/null and b/python/tests/test_files/white_font_color_transparent.png differdiff --git a/python/tests/test_ort.py b/python/tests/test_ort.pyindex ca0e993..45e8971 100644--- a/python/tests/test_ort.py+++ b/python/tests/test_ort.py@@ -20,6 +20,25 @@ img_path = tests_dir / "ch_en_num.jpg"package_name = "rapidocr_onnxruntime"+ "img_name,gt",+ [+ (+ "black_font_color_transparent.png",+ "我是ä¸å›½äºº",+ ),+ (+ "white_font_color_transparent.png",+ "我是ä¸å›½äºº",+ ),+ ],+)+def test_transparent_img(img_name: str, gt: str):+ img_path = tests_dir / img_name+ result, _ = engine(img_path)+ assert result[0][1] == gt++@pytest.mark.parametrize("img_name,gt_len,gt_first_len",[