impr: crop_black_edges

This commit is contained in:
283375 2023-09-13 03:15:34 +08:00
parent 7fb3398608
commit 1f4aaf5728
Signed by: 283375
SSH Key Fingerprint: SHA256:UcX0qg6ZOSDOeieKPGokA5h7soykG61nz2uxuQgVLSk

View File

@ -13,19 +13,17 @@ def crop_xywh(mat: Mat, rect: Tuple[int, int, int, int]):
return mat[y : y + h, x : x + w]
def is_black_edge(list_of_pixels: Mat, black_pixel=None):
if black_pixel is None:
black_pixel = np.array([0, 0, 0], list_of_pixels.dtype)
def is_black_edge(list_of_pixels: Mat, black_pixel: Mat, ratio: float = 0.6):
pixels = list_of_pixels.reshape([-1, 3])
return np.count_nonzero(np.all(pixels < black_pixel, axis=1)) > floor(
len(pixels) * 0.6
len(pixels) * ratio
)
def crop_black_edges(screenshot: Mat):
cropped = screenshot.copy()
black_pixel = np.array([50, 50, 50], screenshot.dtype)
height, width = screenshot.shape[:2]
def crop_black_edges(img_bgr: Mat, black_threshold: int = 50):
cropped = img_bgr.copy()
black_pixel = np.array([black_threshold] * 3, img_bgr.dtype)
height, width = img_bgr.shape[:2]
left = 0
right = width
top = 0