Browse Source

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

Tinger 2 years ago
parent
commit
3856c63faf
1 changed files with 3 additions and 0 deletions
  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)