mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 07:28:21 +08:00
Refactor: Use numpy image cache instead of pillow image
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import re
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from module.base.mask import Mask
|
||||
from module.ui.page import *
|
||||
|
||||
@@ -9,33 +7,18 @@ MASK_MAIN = Mask('./assets/mask/MASK_MAIN.png')
|
||||
MASK_PLAYER = Mask('./assets/mask/MASK_PLAYER.png')
|
||||
|
||||
|
||||
def put_image_mask(image, mask):
|
||||
"""
|
||||
Args:
|
||||
image (PIL.Image.Image):
|
||||
mask (str): Filename
|
||||
|
||||
Returns:
|
||||
PIL.Image.Image:
|
||||
"""
|
||||
mask = Image.open(f'./assets/mask/{mask}.png').convert('L')
|
||||
new = Image.new('RGB', image.size, (0, 0, 0))
|
||||
new.paste(image, box=(0, 0, image.size[0], image.size[1]), mask=mask)
|
||||
return new
|
||||
|
||||
|
||||
def handle_sensitive_image(image):
|
||||
"""
|
||||
Args:
|
||||
image:
|
||||
|
||||
Returns:
|
||||
PIL.Image.Image:
|
||||
np.ndarray:
|
||||
"""
|
||||
if PLAYER_CHECK.match(image, offset=(30, 30)):
|
||||
image = Image.fromarray(MASK_PLAYER.apply(image), mode='RGB')
|
||||
image = MASK_PLAYER.apply(image)
|
||||
if MAIN_CHECK.match(image, offset=(30, 30)):
|
||||
image = Image.fromarray(MASK_MAIN.apply(image), mode='RGB')
|
||||
image = MASK_MAIN.apply(image)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
Reference in New Issue
Block a user