mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-18 13:00:18 +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]
|
return mat[y : y + h, x : x + w]
|
||||||
|
|
||||||
|
|
||||||
def is_black_edge(list_of_pixels: Mat, black_pixel=None):
|
def is_black_edge(list_of_pixels: Mat, black_pixel: Mat, ratio: float = 0.6):
|
||||||
if black_pixel is None:
|
|
||||||
black_pixel = np.array([0, 0, 0], list_of_pixels.dtype)
|
|
||||||
pixels = list_of_pixels.reshape([-1, 3])
|
pixels = list_of_pixels.reshape([-1, 3])
|
||||||
return np.count_nonzero(np.all(pixels < black_pixel, axis=1)) > floor(
|
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):
|
def crop_black_edges(img_bgr: Mat, black_threshold: int = 50):
|
||||||
cropped = screenshot.copy()
|
cropped = img_bgr.copy()
|
||||||
black_pixel = np.array([50, 50, 50], screenshot.dtype)
|
black_pixel = np.array([black_threshold] * 3, img_bgr.dtype)
|
||||||
height, width = screenshot.shape[:2]
|
height, width = img_bgr.shape[:2]
|
||||||
left = 0
|
left = 0
|
||||||
right = width
|
right = width
|
||||||
top = 0
|
top = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user