Commit 079e781e authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): add deprecation to detect_text

parent a091fbb4
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
import font
from imgutils.data import load_image
from imgutils.detect import detect_text
from imgutils.detect.visual import detection_visualize
from imgutils.ocr import ocr
from plot import image_plot


def _detect_with_ocr(img, *, max_size=None, **kwargs):
    img = load_image(img, mode='RGB', force_background='white')
    if max_size is not None and min(img.height, img.width) > max_size:
        r = max_size / min(img.height, img.width)
        img = img.resize((
            int(round(img.width * r)),
            int(round(img.height * r)),
        ))

    return detection_visualize(img, ocr(img, **kwargs), fp=font.get_cn_fp())


def _detect_with_deprecated(img, **kwargs):
    return detection_visualize(img, detect_text(img, **kwargs))


if __name__ == '__main__':
    image_plot(
        (_detect_with_deprecated('text/ml2.jpg'), 'detect_text'),
        (_detect_with_ocr('text/ml2.jpg'), 'detect_text_with_ocr'),
        columns=2,
        figsize=(13, 3.8),
    )
+14 −0
Original line number Diff line number Diff line
@@ -12,14 +12,26 @@ Overview:
    .. image:: text_detect_benchmark.plot.py.svg
        :align: center

    .. warning::
        This module has been deprecated and will be removed in the future.

        It is recommended to migrate to the `imgutils.ocr.detect_text_with_ocr` function as soon as possible.
        This function uses a higher-quality text detection model provided by PaddleOCR,
        resulting in improved performance and higher efficiency.

        .. image:: text_detect_deprecate_demo.plot.py.svg
            :align: center

"""
from functools import lru_cache
from typing import List, Tuple, Optional

import cv2
import numpy as np
from deprecation import deprecated
from huggingface_hub import hf_hub_download

from ..config.meta import __VERSION__
from ..data import ImageTyping, load_image
from ..utils import open_onnx_model

@@ -106,6 +118,8 @@ def _get_bounding_box_of_text(image: ImageTyping, model: str, threshold: float)
    return bboxes


@deprecated(deprecated_in="0.2.10", removed_in="0.4", current_version=__VERSION__,
            details="Use the new function :func:`imgutils.ocr.detect_text_with_ocr` instead")
def detect_text(image: ImageTyping, model: str = _DEFAULT_MODEL, threshold: float = 0.05,
                max_area_size: Optional[int] = 640):
    """
+2 −1
Original line number Diff line number Diff line
@@ -11,3 +11,4 @@ emoji>=2.5.0
pilmoji>=1.3.0
shapely
pyclipper
deprecation>=2.0.0
 No newline at end of file