Skip to content

πŸ“„ Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

test: add unit testings of issue 440 (#445)

SWHLdcbe0d7efa33
diff --git a/python/rapidocr/cal_rec_boxes/main.py b/python/rapidocr/cal_rec_boxes/main.py
index 3ebcb4c..500b387 100644
--- a/python/rapidocr/cal_rec_boxes/main.py
+++ b/python/rapidocr/cal_rec_boxes/main.py
@@ -79,6 +79,7 @@ class CalRecBoxes:
"""
if not rec_txt or word_info.line_txt_len == 0:
return [], [], []
+
bbox_points = quads_to_rect_bbox(bbox[None, ...])
avg_col_width = (bbox_points[2] - bbox_points[0]) / word_info.line_txt_len
@@ -166,8 +167,10 @@ class CalRecBoxes:
) -> float:
if txt_len == 0:
return 0.0
+
if len(width_list) > 0:
return sum(width_list) / len(width_list)
+
return (bbox_x1 - bbox_x0) / txt_len
@staticmethod
diff --git a/python/tests/test_files/return_word_debug.jpg b/python/tests/test_files/return_word_debug.jpg
new file mode 100644
index 0000000..36efd2d
Binary files /dev/null and b/python/tests/test_files/return_word_debug.jpg differ
diff --git a/python/tests/test_main.py b/python/tests/test_main.py
index e9239a4..6bd3e5f 100644
--- a/python/tests/test_main.py
+++ b/python/tests/test_main.py
@@ -448,7 +448,7 @@ def test_cn_word_ocr(engine, img_name: str, words: List[str]):
@pytest.mark.parametrize(
"img_name,words",
- [("issue_170.png", "TEST")],
+ [("issue_170.png", "TEST"), ("return_word_debug.jpg", "3F1")],
)
def test_en_word_ocr(engine, img_name: str, words: str):
img_path = tests_dir / img_name