Explorar o código

v3.7: 图像裁剪结果>=0.3原图

Tinger %!s(int64=2) %!d(string=hai) anos
pai
achega
3856c63faf
Modificáronse 1 ficheiros con 3 adicións e 0 borrados
  1. 3 0
      utils/util.py

+ 3 - 0
utils/util.py

@@ -86,6 +86,9 @@ def crop_img(image: "np.ndarray") -> "np.ndarray":
     if not contours:
         return image
     max_contour = max(contours, key=cv2.contourArea)  # noqa 找到最大的轮廓
+    max_area = cv2.contourArea(max_contour)  # noqa
+    if max_area * 3 < image.shape[0] * image.shape[1]:
+        return image
     rect = cv2.minAreaRect(max_contour)  # noqa 计算最小外接矩形
     box = cv2.boxPoints(rect)  # noqa 获取矩形的四个角点
     box = np.intp(box)