Pref: Reuse image array to improve memory performance

This commit is contained in:
LmeSzinc 2024-06-05 00:20:31 +08:00
parent 77d48937fc
commit 58202c6a40
34 changed files with 61 additions and 58 deletions

View File

@ -36,7 +36,7 @@ class CampaignBase(CampaignBase_):
# Smaller image to run faster
area = (73, 135, 1223, 583)
image = rgb2gray(crop(self.device.image, area=area))
image = rgb2gray(crop(self.device.image, area=area, copy=False))
# E1-1 ~ E1-2
sim, button = TEMPLATE_EVENT_20230817_STORY_E1.match_result(image)

View File

@ -280,7 +280,7 @@ class ModuleBase:
Returns:
Button: Or None if nothing matched.
"""
image = color_similarity_2d(self.image_crop(area), color=color)
image = color_similarity_2d(self.image_crop(area, copy=False), color=color)
points = np.array(np.where(image > color_threshold)).T[:, ::-1]
if points.shape[0] < encourage ** 2:
# Not having enough pixels to match

View File

@ -115,7 +115,7 @@ class CampaignOcr(ModuleBase):
@cached_property
def _stage_image(self):
return crop(self.device.image, self._stage_detect_area)
return crop(self.device.image, self._stage_detect_area, copy=False)
@cached_property
def _stage_image_gray(self):
@ -270,6 +270,8 @@ class CampaignOcr(ModuleBase):
del_cached_property(self, '_stage_image')
del_cached_property(self, '_stage_image_gray')
buttons = self.campaign_extract_name_image(image)
del_cached_property(self, '_stage_image')
del_cached_property(self, '_stage_image_gray')
if len(buttons) == 0:
logger.info('No stage found.')
raise CampaignNameError

View File

@ -217,7 +217,7 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
scanner.set_limitation(fleet=0)
candidates = [ship for ship in scanner.scan(self.device.image, output=False)
if template.match(self.image_crop(ship.button), similarity=SIM_VALUE)]
if template.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]
if candidates:
return candidates
@ -226,7 +226,7 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
self.dock_sort_method_dsc_set(False)
candidates = [ship for ship in scanner.scan(self.device.image)
if template.match(self.image_crop(ship.button), similarity=SIM_VALUE)]
if template.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]
return candidates
@ -279,7 +279,7 @@ class GemsFarming(CampaignRun, FleetEquipment, Dock):
candidates = []
for item in template:
candidates = [ship for ship in scanner.scan(self.device.image, output=False)
if item.match(self.image_crop(ship.button), similarity=SIM_VALUE)]
if item.match(self.image_crop(ship.button, copy=False), similarity=SIM_VALUE)]
if candidates:
break
return candidates

View File

@ -66,7 +66,7 @@ class Combat(Level, HPBalancer, Retirement, SubmarineCall, CombatAuto, CombatMan
Returns:
bool:
"""
similarity, button = TEMPLATE_COMBAT_LOADING.match_result(self.image_crop((0, 620, 1280, 720)))
similarity, button = TEMPLATE_COMBAT_LOADING.match_result(self.image_crop((0, 620, 1280, 720), copy=False))
if similarity > 0.85:
loading = (button.area[0] + 38 - LOADING_BAR.area[0]) / (LOADING_BAR.area[2] - LOADING_BAR.area[0])
logger.attr('Loading', f'{int(loading * 100)}%')
@ -82,7 +82,7 @@ class Combat(Level, HPBalancer, Retirement, SubmarineCall, CombatAuto, CombatMan
self.device.stuck_record_add(PAUSE)
color = get_color(self.device.image, PAUSE.area)
if color_similar(color, PAUSE.color) or color_similar(color, (238, 244, 248)):
if np.max(self.image_crop(PAUSE_DOUBLE_CHECK)) < 153:
if np.max(self.image_crop(PAUSE_DOUBLE_CHECK, copy=False)) < 153:
return True
return False

View File

@ -39,7 +39,7 @@ def lines_detect(image):
"""
# Find white lines under each commission to locate them.
# (597, 0, 619, 720) is somewhere with white lines only.
color_height = np.mean(rgb2gray(crop(image, (597, 0, 619, 720))), axis=1)
color_height = np.mean(rgb2gray(crop(image, (597, 0, 619, 720), copy=False)), axis=1)
parameters = {'height': 200, 'distance': 100}
peaks, _ = signal.find_peaks(color_height, **parameters)
# 67 is the height of commission list header
@ -97,7 +97,7 @@ class RewardCommission(UI, InfoHandler):
image = self.device.image
if area is not None:
image = crop(image, area)
image = crop(image, area, copy=False)
commissions = self._commission_detect(image)
if commissions.count >= 2 and commissions.select(valid=False).count == 1:

View File

@ -294,7 +294,7 @@ class RewardDorm(UI):
return Digit(grids.buttons, letter=(255, 255, 255), threshold=128, name='OCR_DORM_FOOD')
def _dorm_has_food(self, button):
return np.min(rgb2gray(self.image_crop(button))) < 127
return np.min(rgb2gray(self.image_crop(button, copy=False))) < 127
def _dorm_feed_click(self, button, count):
"""

View File

@ -52,7 +52,7 @@ class EquipmentChange(Equipment):
for index, button in enumerate(EQUIPMENT_GRID.buttons):
if index not in index_list:
continue
crop_image = self.image_crop(button)
crop_image = self.image_crop(button, copy=False)
edge_value = np.mean(np.abs(cv2.Sobel(crop_image, 3, 1, 1)))
# Nothing is 0.15~1
# +1 is 40

View File

@ -18,7 +18,7 @@ class GuildLobby(GuildBase):
Button: Button to enter guild report.
"""
# Find red color in the area of GUILD_REPORT_AVAILABLE
image = color_similarity_2d(self.image_crop(GUILD_REPORT_AVAILABLE), color=(255, 8, 8))
image = color_similarity_2d(self.image_crop(GUILD_REPORT_AVAILABLE, copy=False), color=(255, 8, 8))
points = np.array(np.where(image > 221)).T[:, ::-1]
if len(points):
# The center of red dot

View File

@ -157,7 +157,7 @@ class GuildOperations(GuildBase):
list_expand = []
list_enter = []
dots = TEMPLATE_OPERATIONS_RED_DOT.match_multi(self.image_crop(detection_area), threshold=5)
dots = TEMPLATE_OPERATIONS_RED_DOT.match_multi(self.image_crop(detection_area, copy=False), threshold=5)
logger.info(f'Active operations found: {len(dots)}')
for button in dots:
button = button.move(vector=detection_area[:2])

View File

@ -71,7 +71,7 @@ class AmbushHandler(Combat):
continue
# Handle evade success and failures
image = info_letter_preprocess(self.image_crop(INFO_BAR_DETECT))
image = info_letter_preprocess(self.image_crop(INFO_BAR_DETECT, copy=False))
if TEMPLATE_AMBUSH_EVADE_SUCCESS.match(image):
logger.attr('Ambush_evade', 'success')
elif TEMPLATE_AMBUSH_EVADE_FAILED.match(image):
@ -140,7 +140,7 @@ class AmbushHandler(Combat):
if not self.info_bar_count():
return False
image = info_letter_preprocess(self.image_crop(INFO_BAR_DETECT))
image = info_letter_preprocess(self.image_crop(INFO_BAR_DETECT, copy=False))
if TEMPLATE_MAP_WALK_OUT_OF_STEP.match(image):
logger.warning('Map walk out of step.')
self.handle_info_bar()

View File

@ -8,7 +8,7 @@ from module.exception import GameNotRunningError
from module.handler.assets import *
from module.logger import logger
from module.os_handler.assets import CLICK_SAFE_AREA as OS_CLICK_SAFE_AREA
from module.ui_white.assets import POPUP_SINGLE_WHITE, POPUP_CONFIRM_WHITE, POPUP_CANCEL_WHITE
from module.ui_white.assets import POPUP_CANCEL_WHITE, POPUP_CONFIRM_WHITE, POPUP_SINGLE_WHITE
def info_letter_preprocess(image):
@ -42,7 +42,7 @@ class InfoHandler(ModuleBase):
Returns:
int:
"""
image = self.image_crop(INFO_BAR_AREA)
image = self.image_crop(INFO_BAR_AREA, copy=False)
line = cv2.reduce(image, 1, cv2.REDUCE_AVG)
line = color_similarity_2d(line, color=(107, 158, 255))[:, 0]
@ -294,7 +294,7 @@ class InfoHandler(ModuleBase):
story_option_area = (730, 188, 1140, 480)
# Background color of the left part of the option.
story_option_color = (99, 121, 156)
image = color_similarity_2d(self.image_crop(story_option_area), color=story_option_color) > 225
image = color_similarity_2d(self.image_crop(story_option_area, copy=False), color=story_option_color) > 225
x_count = np.where(np.sum(image, axis=0) > 40)[0]
if not len(x_count):
return []
@ -335,7 +335,7 @@ class InfoHandler(ModuleBase):
story_detect_area = (330, 200, 355, 465)
story_option_color = (247, 247, 247)
image = color_similarity_2d(self.image_crop(story_detect_area), color=story_option_color)
image = color_similarity_2d(self.image_crop(story_detect_area, copy=False), color=story_option_color)
line = cv2.reduce(image, 1, cv2.REDUCE_AVG).flatten()
line[line < 200] = 0
line[line >= 200] = 255

View File

@ -225,7 +225,8 @@ class LoginHandler(UI):
XPS('//*[@content-desc="请滑动阅读协议内容"]', xp, hierarchy)])
test_image_original = self.device.image
image_handle_crop = crop(test_image_original, (start_padding_results[2], 0, start_margin_results[2], 720))
image_handle_crop = crop(
test_image_original, (start_padding_results[2], 0, start_margin_results[2], 720), copy=False)
# Image.fromarray(image_handle_crop).show()
sims = color_similarity_2d(image_handle_crop, color=(182, 189, 202))
points = np.sum(sims >= 255)

View File

@ -123,7 +123,7 @@ class StrategyHandler(InfoHandler):
Returns:
int: Formation index.
"""
image = self.image_crop(MAP_BUFF)
image = self.image_crop(MAP_BUFF, copy=False)
if TEMPLATE_FORMATION_2.match(image):
buff = 'double_line'
elif TEMPLATE_FORMATION_1.match(image):

View File

@ -114,7 +114,7 @@ class FleetOperator:
return None
area = self._hard_satisfied.button
image = color_similarity_2d(self.main.image_crop(area), color=(249, 199, 0))
image = color_similarity_2d(self.main.image_crop(area, copy=False), color=(249, 199, 0))
height = cv2.reduce(image, 1, cv2.REDUCE_AVG).flatten()
parameters = {'height': 180, 'distance': 5}
peaks, _ = signal.find_peaks(height, **parameters)
@ -230,7 +230,7 @@ class FleetOperator:
Returns:
list: List of int. Currently selected fleet ranges from 1 to 6.
"""
data = self.parse_fleet_bar(self.main.image_crop(self._bar.button))
data = self.parse_fleet_bar(self.main.image_crop(self._bar.button, copy=False))
return data
def in_use(self):
@ -244,7 +244,7 @@ class FleetOperator:
# Cropping FLEET_*_IN_USE to avoid detecting info_bar, also do the trick.
# It also avoids wasting time on handling the info_bar.
image = rgb2gray(self.main.image_crop(self._in_use.button))
image = rgb2gray(self.main.image_crop(self._in_use.button, copy=False))
return np.std(image.flatten(), ddof=1) > self.FLEET_IN_USE_STD
def bar_opened(self):
@ -253,7 +253,7 @@ class FleetOperator:
bool: If dropdown menu appears.
"""
# Check the brightness of the rightest column of the bar area.
luma = rgb2gray(self.main.image_crop(self._bar.button))[:, -1]
luma = rgb2gray(self.main.image_crop(self._bar.button, copy=False))[:, -1]
# FLEET_PREPARATION is about 146~155
return np.sum(luma > 168) / luma.size > 0.5

View File

@ -271,7 +271,7 @@ class GridPredictor:
def predict_sea(self):
area = area_pad((48, 48, 48 + 46, 48 + 46), pad=5)
res = cv2.matchTemplate(ASSETS.tile_center_image, crop(self.image_homo, area=area), cv2.TM_CCOEFF_NORMED)
res = cv2.matchTemplate(ASSETS.tile_center_image, crop(self.image_homo, area=area, copy=False), cv2.TM_CCOEFF_NORMED)
_, sim, _, _ = cv2.minMaxLoc(res)
if sim > 0.8:
return True
@ -281,7 +281,7 @@ class GridPredictor:
corner = [(5, 5, corner, corner), (tile - corner, 5, tile, corner), (5, tile - corner, corner, tile),
(tile - corner, tile - corner, tile, tile)]
for area, template in zip(corner[::-1], ASSETS.tile_corner_image_list[::-1]):
res = cv2.matchTemplate(template, crop(self.image_homo, area=area), cv2.TM_CCOEFF_NORMED)
res = cv2.matchTemplate(template, crop(self.image_homo, area=area, copy=False), cv2.TM_CCOEFF_NORMED)
_, sim, _, _ = cv2.minMaxLoc(res)
if sim > 0.8:
return True

View File

@ -188,7 +188,7 @@ class OSGridPredictor(GridPredictor):
return False
area = area_pad((48, 48, 48 + 46, 48 + 46), pad=5)
res = cv2.matchTemplate(ASSETS.tile_center_image, crop(self.image_homo, area=area), cv2.TM_CCOEFF_NORMED)
res = cv2.matchTemplate(ASSETS.tile_center_image, crop(self.image_homo, area=area, copy=False), cv2.TM_CCOEFF_NORMED)
_, sim, _, _ = cv2.minMaxLoc(res)
if sim > 0.8:
return True
@ -285,7 +285,7 @@ class OSGridPredictor(GridPredictor):
h = (185, 195)
s = (15, 90)
v = (60, 100)
image = cv2.cvtColor(crop(self.image, area), cv2.COLOR_RGB2HSV)
image = cv2.cvtColor(crop(self.image, area, copy=False), cv2.COLOR_RGB2HSV)
lower = (h[0] / 2, s[0] * 2.55, v[0] * 2.55)
upper = (h[1] / 2 + 1, s[1] * 2.55 + 1, v[1] * 2.55 + 1)
image = cv2.inRange(image, lower, upper)
@ -298,7 +298,7 @@ class OSGridPredictor(GridPredictor):
# Should also have random white rectangles
area = self.grid2screen(np.array([(0.2, 0.2), (0.8, 0.8)]))
area = np.rint(area.flatten()).astype(int).tolist()
image = color_similarity_2d(crop(self.image, area), color=(255, 255, 255))
image = color_similarity_2d(crop(self.image, area, copy=False), color=(255, 255, 255))
count = image[image > 221].shape[0]
if count < 30:
return False

View File

@ -176,7 +176,7 @@ class OSFleet(OSCamera, Combat, Fleet, OSAsh):
"""
super().hp_get()
ship_icon = self._hp_grid().crop((0, -67, 67, 0))
need_repair = [TEMPLATE_EMPTY_HP.match(self.image_crop(button)) for button in ship_icon.buttons]
need_repair = [TEMPLATE_EMPTY_HP.match(self.image_crop(button, copy=False)) for button in ship_icon.buttons]
self.need_repair = need_repair
logger.attr('Repair icon', need_repair)

View File

@ -234,7 +234,7 @@ class GlobeCamera(GlobeOperation, ZoneManager):
screen = self.globe2screen(location).flatten().round()
screen = np.round(screen).astype(int).tolist()
# Average color of whirlpool center
center = self.image_crop(screen)
center = self.image_crop(screen, copy=False)
center = np.array([[cv2.mean(center), ], ]).astype(np.uint8)
h, s, v = rgb2hsv(center)[0][0]
# hsv usually to be (338, 74.9, 100)

View File

@ -67,7 +67,7 @@ class FleetSelector:
Returns:
list: List of int. Currently selected fleet ranges from 1 to 4.
"""
data = self.parse_fleet_bar(self.main.image_crop(self._bar))
data = self.parse_fleet_bar(self.main.image_crop(self._bar, copy=False))
return data
def get_button(self, index):

View File

@ -116,7 +116,7 @@ class RadarGrid:
Returns:
bool:
"""
image = crop(self.image, area_offset(area, self.center))
image = crop(self.image, area_offset(area, self.center), copy=False)
mask = color_similarity_2d(image, color=color) > threshold
return np.sum(mask) >= count
@ -236,7 +236,7 @@ class Radar:
Or None if port not found.
"""
radius = (15, 82)
image = crop(image, area_offset((-radius[1], -radius[1], radius[1], radius[1]), self.center))
image = crop(image, area_offset((-radius[1], -radius[1], radius[1], radius[1]), self.center), copy=False)
# image.show()
points = np.where(color_similarity_2d(image, color=(255, 255, 255)) > 250)
points = np.array(points).T[:, ::-1] - (radius[1], radius[1])

View File

@ -164,7 +164,7 @@ class MapOrderHandler(MapOperation, ActionPointHandler, MapEventHandler, ZoneMan
"""
if not self.map_cat_attack_timer.reached():
return False
if np.sum(color_similarity_2d(self.image_crop(MAP_CAT_ATTACK), (255, 231, 123)) > 221) > 100:
if np.sum(color_similarity_2d(self.image_crop(MAP_CAT_ATTACK, copy=False), (255, 231, 123)) > 221) > 100:
logger.info('Skip map cat attack')
self.device.click(CLICK_SAFE_AREA)
self.map_cat_attack_timer.reset()

View File

@ -26,7 +26,7 @@ class MissionHandler(GlobeOperation, ZoneManager):
"""
area = (341, 72, 1217, 648)
# Points of the yellow `!`
image = color_similarity_2d(self.image_crop(area), color=(255, 207, 66))
image = color_similarity_2d(self.image_crop(area, copy=False), color=(255, 207, 66))
points = np.array(np.where(image > 235)).T[:, ::-1]
if not len(points):
logger.warning('Unable to find mission on OS mission map')

View File

@ -45,7 +45,7 @@ def get_research_series_old(image, series_button=RESEARCH_SERIES):
parameters = {'height': 160, 'prominence': 50, 'width': 1}
for button in series_button:
im = color_similarity_2d(resize(crop(image, button.area), (46, 25)), color=(255, 255, 255))
im = color_similarity_2d(resize(crop(image, button.area, copy=False), (46, 25)), color=(255, 255, 255))
peaks = [len(signal.find_peaks(row, **parameters)[0]) for row in im[5:-5]]
upper, lower = max(peaks), min(peaks)
# print(peaks)
@ -116,7 +116,7 @@ def get_research_series(image, series_button=RESEARCH_SERIES):
result = []
for button in series_button:
# img = resize(crop(image, button.area), (46, 25))
img = crop(image, button.area)
img = crop(image, button.area, copy=False)
img = cv2.resize(img, (46, 25), interpolation=cv2.INTER_AREA)
series = _get_research_series(img)
result.append(series)
@ -195,7 +195,7 @@ def match_template(image, template, area, offset=30, threshold=0.85):
offset = np.array((-offset[0], -offset[1], offset[0], offset[1]))
else:
offset = np.array((0, -offset, 0, offset))
image = crop(image, offset + area)
image = crop(image, offset + area, copy=False)
res = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
_, sim, _, point = cv2.minMaxLoc(res)
similarity = sim if sim >= threshold else 0.0
@ -217,7 +217,7 @@ def get_research_series_jp_old(image):
area = SERIES_DETAIL.area
# Resize is not needed because only one area will be checked in JP server.
im = color_similarity_2d(crop(image, area), color=(255, 255, 255))
im = color_similarity_2d(crop(image, area, copy=False), color=(255, 255, 255))
peaks = [len(signal.find_peaks(row, **parameters)[0]) for row in im[5:-5]]
upper, lower = max(peaks), min(peaks)
# print(upper, lower)
@ -303,7 +303,7 @@ def get_research_cost_jp(image):
costs = {'coin': False, 'cube': False, 'plate': False}
for name, template in templates.items():
template = load_image(template)
template = crop(resize(template, size_template), area_template)
template = crop(resize(template, size_template), area_template, copy=False)
sim = match_template(image=image,
template=template,
area=DETAIL_COST.area,

View File

@ -200,7 +200,7 @@ class RewardResearch(ResearchSelector, ResearchQueue, StorageHandler):
else:
self.device.screenshot()
max_rgb = np.max(rgb2gray(self.image_crop(RESEARCH_UNAVAILABLE)))
max_rgb = np.max(rgb2gray(self.image_crop(RESEARCH_UNAVAILABLE, copy=False)))
# Don't use interval here, RESEARCH_CHECK already appeared 5 seconds ago
if click_timer.reached() and self.is_in_research():

View File

@ -41,7 +41,7 @@ def get_research_series_3(image, series_button=RESEARCH_SERIES):
list[int]:
"""
return [
match_series(crop(image, area_pad(button.area, pad=-10)), scaling)
match_series(crop(image, area_pad(button.area, pad=-10), copy=False), scaling)
for scaling, button in zip(RESEARCH_SCALING, series_button)
]
@ -54,4 +54,4 @@ def get_detail_series(image):
Returns:
int:
"""
return match_series(crop(image, area_pad(SERIES_DETAIL.area, pad=-30)), scaling=1.0)
return match_series(crop(image, area_pad(SERIES_DETAIL.area, pad=-30), copy=False), scaling=1.0)

View File

@ -86,7 +86,7 @@ class ResearchUI(UI):
out = []
for index, status, scaling in zip(range(5), RESEARCH_STATUS, RESEARCH_SCALING):
info = status.crop((0, -40, 200, 0))
piece = rgb2gray(crop(image, info.area))
piece = rgb2gray(crop(image, info.area, copy=False))
if TEMPLATE_WAITING.match(piece, scaling=scaling, similarity=0.75):
out.append('waiting')
elif TEMPLATE_RUNNING.match(piece, scaling=scaling, similarity=0.75):

View File

@ -439,7 +439,7 @@ class DockScanner(ShipScanner):
# Roughly Adjust
# After graying the image, calculate the standard deviation and take the part below the threshold
# Those parts should present multiple discontinuous subsequences, which here called gap_seq
scan_image = crop(image, self.scan_zone)
scan_image = crop(image, self.scan_zone, copy=False)
def find_bound(image):
bound = []
@ -454,7 +454,7 @@ class DockScanner(ShipScanner):
bound = [0] + bound
return bound
bounds = [find_bound(crop(scan_image, button.area)) for button in self.scan_grids.buttons]
bounds = [find_bound(crop(scan_image, button.area, copy=False)) for button in self.scan_grids.buttons]
card_bottom = (np.mean(bounds, axis=0) + 0.5).astype(np.uint8)
# Calculate the bound of gap_seq, usually we get 3 endpoints
# The offset is the difference between the two groups of endpoints

View File

@ -43,7 +43,7 @@ class MedalShop2(ShopClerk, ShopStatus):
Returns:
np.array: [[x1, y1], [x2, y2]], location of the medal icon upper-left corner.
"""
left_column = self.image_crop((472, 348, 1170, 648))
left_column = self.image_crop((472, 348, 1170, 648), copy=False)
medals = TEMPLATE_MEDAL_ICON_2.match_multi(left_column, similarity=0.5, threshold=5)
medals = Points([(0., m.area[1]) for m in medals]).group(threshold=5)
logger.attr('Medals_icon', len(medals))

View File

@ -29,7 +29,7 @@ class VoucherShop(ShopClerk, ShopStatus):
Returns:
np.array: [[x1, y1], [x2, y2]], location of the voucher icon upper-left corner.
"""
left_column = self.image_crop((305, 306, 1256, 646))
left_column = self.image_crop((305, 306, 1256, 646), copy=False)
vouchers = TEMPLATE_VOUCHER_ICON.match_multi(left_column, similarity=0.75, threshold=5)
vouchers = Points([(0., v.area[1]) for v in vouchers]).group(threshold=5)
logger.attr('Vouchers_icon', len(vouchers))

View File

@ -178,7 +178,7 @@ class CampaignSos(CampaignRun, CampaignBase):
self.device.screenshot()
if self.appear(SIGNAL_LIST_CHECK, offset=(20, 20), interval=2):
image = self.image_crop(area_pad(entrance.area, pad=-30))
image = self.image_crop(area_pad(entrance.area, pad=-30), copy=False)
if TEMPLATE_SIGNAL_SEARCH.match(image):
self.device.click(entrance)
if TEMPLATE_SIGNAL_GOTO.match(image):

View File

@ -36,7 +36,7 @@ class GetItemsStatistics:
Returns:
bool: If the number of items in row is odd.
"""
image = crop(image, GET_ITEMS_ODD.area)
image = crop(image, GET_ITEMS_ODD.area, copy=False)
return np.mean(rgb2gray(image) > 127) > 0.1
def _stats_get_items_load(self, image):

View File

@ -130,7 +130,7 @@ class Book:
image (np.ndarray):
button (Button):
"""
image = crop(image, button.area)
image = crop(image, button.area, copy=False)
self.button = button
# During the test of 40 random screenshots,
@ -148,7 +148,7 @@ class Book:
if color_similar(color1=color, color2=value, threshold=50):
self.tier = key
color = color_similarity_2d(crop(image, (15, 0, 97, 13)), color=(148, 251, 99))
color = color_similarity_2d(crop(image, (15, 0, 97, 13), copy=False), color=(148, 251, 99))
self.exp = bool(np.sum(color > 221) > 50)
self.valid = bool(self.genre and self.tier)
@ -166,7 +166,7 @@ class Book:
"""
area = self.button.area
check_area = tuple([area[0], area[3] + 2, area[2], area[3] + 4])
im = rgb2gray(crop(image, check_area))
im = rgb2gray(crop(image, check_area, copy=False))
return True if np.mean(im) > 127 else False
def __str__(self):
@ -534,7 +534,7 @@ class RewardTacticalClass(Dock):
def check_skill_selected(button, image):
area = button.area
check_area = tuple([area[0], area[3] + 2, area[2], area[3] + 4])
im = rgb2gray(crop(image, check_area))
im = rgb2gray(crop(image, check_area, copy=False))
return True if np.mean(im) > 127 else False
def _tactical_skill_choose(self):

View File

@ -47,7 +47,7 @@ class Scroll:
Returns:
np.ndarray: Shape (n,), dtype bool.
"""
image = main.image_crop(self.area)
image = main.image_crop(self.area, copy=False)
image = color_similarity_2d(image, color=self.color)
mask = np.max(image, axis=1 if self.is_vertical else 0) > self.color_threshold
self.length = np.sum(mask)