📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Fixed issue #158
SWHLe388bd9b036b
diff --git a/python/rapidocr_openvino/utils.py b/python/rapidocr_openvino/utils.pyindex ad2090d..7c03cff 100644--- a/python/rapidocr_openvino/utils.py+++ b/python/rapidocr_openvino/utils.py@@ -135,7 +135,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/rapidocr_paddle/utils.py b/python/rapidocr_paddle/utils.pyindex cc4a339..78476fb 100644--- a/python/rapidocr_paddle/utils.py+++ b/python/rapidocr_paddle/utils.py@@ -217,7 +217,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_paddle.py b/python/tests/test_paddle.pyindex 403d183..91edb99 100644--- a/python/tests/test_paddle.py+++ b/python/tests/test_paddle.py@@ -20,6 +20,25 @@ img_path = tests_dir / "ch_en_num.jpg"package_name = "rapidocr_paddle"+ "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",[diff --git a/python/tests/test_vino.py b/python/tests/test_vino.pyindex 3ea998e..113f17d 100644--- a/python/tests/test_vino.py+++ b/python/tests/test_vino.py@@ -20,6 +20,25 @@ img_path = tests_dir / "ch_en_num.jpg"package_name = "rapidocr_openvino"+ "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",[