Commit 14f7cfa4 authored by narugo1992's avatar narugo1992
Browse files

Merge branch 'main' into dev/tagging

parents 617289a3 4e86e054
Loading
Loading
Loading
Loading
+9.58 MiB

File added.

No diff preview for this file type.

+8 −0
Original line number Diff line number Diff line
import os.path

import matplotlib.font_manager as fm


def get_cn_fp() -> fm.FontProperties:
    ttf_file = os.path.join(os.path.dirname(__file__), 'SimHei.ttf')
    return fm.FontProperties(fname=ttf_file)
+1 −6
Original line number Diff line number Diff line
@@ -57,11 +57,6 @@ def image_plot(*images, save_as: str, columns=2, keep_axis: bool = False, figsiz
    for i, img in enumerate(images, start=0):
        xi, yi = i // columns, i % columns
        image, label = _image_input_process(img, autocensor)
        if rows == 1 and columns == 1:
            ax = axs
        elif rows == 1:
            ax = axs[yi]
        else:
        ax = axs[xi, yi]
        ax.imshow(image)
        ax.set_title(label)
+9.58 MiB

File added.

No diff preview for this file type.

+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),
    )
Loading