mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-11 09:30:17 +00:00
impr: crop_black_edges
This commit is contained in:
parent
7fb3398608
commit
1f4aaf5728
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user