浏览代码

use simfang font in ocr pipeline (#3243)

Tingquan Gao 9 月之前
父节点
当前提交
7db048b11b
共有 3 个文件被更改,包括 8 次插入7 次删除
  1. 2 2
      paddlex/inference/pipelines/ocr/result.py
  2. 6 5
      paddlex/utils/fonts/__init__.py
  3. 二进制
      paddlex/utils/fonts/simfang.ttf

+ 2 - 2
paddlex/inference/pipelines/ocr/result.py

@@ -22,7 +22,7 @@ import numpy as np
 import cv2
 import PIL
 from PIL import Image, ImageDraw, ImageFont
-from ....utils.fonts import PINGFANG_FONT_FILE_PATH, create_font
+from ....utils.fonts import SIMFANG_FONT_FILE_PATH, create_font
 from ...common.result import BaseCVResult, StrMixin, JsonMixin
 
 
@@ -105,7 +105,7 @@ class OCRResult(BaseCVResult):
                     box[2:, 1] = np.mean(box[:, 1]) + min(20, height)
                 draw_left.polygon(box, fill=color)
                 img_right_text = draw_box_txt_fine(
-                    (w, h), box, txt, PINGFANG_FONT_FILE_PATH
+                    (w, h), box, txt, SIMFANG_FONT_FILE_PATH
                 )
                 pts = np.array(box, np.int32).reshape((-1, 1, 2))
                 cv2.polylines(img_right_text, [pts], True, color, 1)

+ 6 - 5
paddlex/utils/fonts/__init__.py

@@ -19,15 +19,15 @@ import PIL
 from PIL import ImageFont
 
 
-def get_pingfang_file_path() -> str:
+def get_font_file_path(file_name: str) -> str:
     """
-    Get the path of the PingFang font file.
+    Get the path of the font file.
 
     Returns:
-    str: The path to the PingFang font file.
+    str: The path to the font file.
     """
 
-    return (Path(__file__).parent / "PingFang-SC-Regular.ttf").resolve().as_posix()
+    return (Path(__file__).parent / file_name).resolve().as_posix()
 
 
 def create_font(txt: str, sz: tuple, font_path: str) -> ImageFont:
@@ -56,4 +56,5 @@ def create_font(txt: str, sz: tuple, font_path: str) -> ImageFont:
     return font
 
 
-PINGFANG_FONT_FILE_PATH = get_pingfang_file_path()
+PINGFANG_FONT_FILE_PATH = get_font_file_path("PingFang-SC-Regular.ttf")
+SIMFANG_FONT_FILE_PATH = get_font_file_path("simfang.ttf")

二进制
paddlex/utils/fonts/simfang.ttf