Bladeren bron

feat(新增水印检测和去除功能): 添加水印检测和去除的兼容别名,迁移至水印工具模块

zhch158_admin 1 week geleden
bovenliggende
commit
e92c162db4
1 gewijzigde bestanden met toevoegingen van 44 en 1 verwijderingen
  1. 44 1
      ocr_utils/image_utils.py

+ 44 - 1
ocr_utils/image_utils.py

@@ -7,10 +7,11 @@
 - 图像预处理
 - BBox 和点坐标转换
 - 图像旋转和坐标转换
+- 水印去除
 """
 import cv2
 import numpy as np
-from typing import List, Tuple, Union
+from typing import List, Tuple, Union, Optional, Dict, Any
 from PIL import Image
 
 
@@ -113,6 +114,48 @@ def points_to_bbox(points: np.ndarray) -> List[float]:
     return [x0, y0, x1, y1]
 
 
+def detect_watermark(
+    image: Union[np.ndarray, Image.Image],
+    midtone_low: int = 100,
+    midtone_high: int = 220,
+    ratio_threshold: float = 0.03,
+    check_diagonal: bool = True,
+    diagonal_angle_range: tuple = (30, 60),
+) -> bool:
+    """向后兼容别名,实现已迁移至 ocr_utils.watermark_utils.detect_watermark。"""
+    from ocr_utils.watermark_utils import detect_watermark as _impl
+    return _impl(
+        image,
+        midtone_low=midtone_low,
+        midtone_high=midtone_high,
+        ratio_threshold=ratio_threshold,
+        check_diagonal=check_diagonal,
+        diagonal_angle_range=diagonal_angle_range,
+    )
+
+
+def remove_watermark_from_image(
+    image: Union[np.ndarray, Image.Image],
+    threshold: int = 160,
+    morph_close_kernel: int = 2,
+    return_pil: Optional[bool] = None,
+) -> Union[np.ndarray, Image.Image]:
+    """向后兼容别名,实现已迁移至 ocr_utils.watermark_utils.remove_watermark_from_image。"""
+    from ocr_utils.watermark_utils import remove_watermark_from_image as _impl
+    return _impl(image, threshold=threshold, morph_close_kernel=morph_close_kernel, return_pil=return_pil)
+
+
+def remove_watermark_from_image_rgb(
+    image: Union[np.ndarray, Image.Image],
+    threshold: int = 160,
+    morph_close_kernel: int = 2,
+    return_pil: Optional[bool] = None,
+) -> Union[np.ndarray, Image.Image]:
+    """向后兼容别名,实现已迁移至 ocr_utils.watermark_utils.remove_watermark_from_image_rgb。"""
+    from ocr_utils.watermark_utils import remove_watermark_from_image_rgb as _impl
+    return _impl(image, threshold=threshold, morph_close_kernel=morph_close_kernel, return_pil=return_pil)
+
+
 def rotate_image_and_coordinates(
     image: Image.Image, 
     angle: float,