Files
rapidocr/python/tests/test_det_preprocess.py
T
Mohammad Hijjawi f65c7da00e fix(det): honour limit_side_len when limit_type is max (issue #740) (#742)
TextDetector.get_preprocess replaced limit_side_len with a hard-coded
960/1500/2000 bucket whenever limit_type was "max", so the configured
value was ignored and large images reached the detector unresized.
Pass the configured limit_side_len through for both limit types, matching
PaddleOCR DetResizeForTest.
2026-10-03 06:36:38 +08:00

44 lines
1.3 KiB
Python

# -*- encoding: utf-8 -*-
# @Author: Mohammad Hijjawi
import numpy as np
import pytest
from rapidocr.ch_ppocr_det import TextDetector
def get_detector(limit_side_len: int, limit_type: str) -> TextDetector:
detector = TextDetector.__new__(TextDetector)
detector.limit_side_len = limit_side_len
detector.limit_type = limit_type
detector.mean = [0.5, 0.5, 0.5]
detector.std = [0.5, 0.5, 0.5]
detector.postprocess_op = lambda preds, ori_shape: ([], [])
return detector
@pytest.mark.parametrize(
"limit_side_len,limit_type,img_hw,expected_hw",
[
# issue #740: limit_side_len must be honoured when limit_type is "max"
(960, "max", (2000, 2000), (960, 960)),
(960, "max", (1000, 2000), (480, 960)),
(640, "max", (1200, 800), (640, 416)),
(960, "max", (320, 640), (320, 640)),
(736, "min", (500, 1000), (736, 1472)),
(736, "min", (1000, 800), (992, 800)),
(736, "min", (800, 1600), (800, 1600)),
],
)
def test_det_preprocess_respects_limit_side_len(
limit_side_len, limit_type, img_hw, expected_hw
):
detector = get_detector(limit_side_len, limit_type)
img = np.zeros((*img_hw, 3), dtype=np.uint8)
det_inputs = []
detector.session = det_inputs.append
detector(img)
assert len(det_inputs) == 1
assert det_inputs[0].shape == (1, 3, *expected_hw)