From 7bd04136101dd80c657f75a1154849e153503435 Mon Sep 17 00:00:00 2001 From: sui-feng-cb <2518179942@qq.com> Date: Thu, 4 Dec 2025 19:23:50 +0800 Subject: [PATCH] Upd: threshold for predict_valid in campaign_bonus --- module/statistics/campaign_bonus.py | 8 +++++++- module/statistics/drop_statistics.py | 6 +++--- module/statistics/item.py | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/module/statistics/campaign_bonus.py b/module/statistics/campaign_bonus.py index ef415e364..1351093b7 100644 --- a/module/statistics/campaign_bonus.py +++ b/module/statistics/campaign_bonus.py @@ -9,7 +9,13 @@ from module.statistics.utils import * class BonusItem(Item): def predict_valid(self): - return np.mean(rgb2gray(self.image) > 160) > 0.3 + image = rgb2gray(self.image) + width, height = image_size(image) + wm, hm = width // 2, height // 2 + row_center = image[hm: hm + 5, :] + info_bar = image[64: 69, :] + column_center = image[:, wm: wm + 5] + return all(np.mean(img > 160) > 0.1 for img in [image, row_center, info_bar, column_center]) class CampaignBonusStatistics(GetItemsStatistics): diff --git a/module/statistics/drop_statistics.py b/module/statistics/drop_statistics.py index 42750f798..f468b8315 100644 --- a/module/statistics/drop_statistics.py +++ b/module/statistics/drop_statistics.py @@ -120,7 +120,7 @@ class DropStatistics: if self.campaign_bonus.appear_on(image, similarity=similarity): for button in [CAMPAIGN_BONUS_SINGLE, CAMPAIGN_BONUS]: self.campaign_bonus.bonus_button = button - for item in self.campaign_bonus.stats_get_items(image): + for item in self.campaign_bonus.stats_get_items(image, mode='known'): yield [ts, campaign, enemy_name, button.name, item.name, item.amount] else: raise ImageError('No campaign bonus on image.') @@ -135,7 +135,7 @@ class DropStatistics: print('') logger.hr(f'Extract templates from {campaign}', level=1) self.check_server(campaign) - for ts, file in tqdm(load_folder(self.drop_folder(campaign)).items()): + for ts, file in tqdm(load_folder(self.drop_folder(campaign), ext=['.png', '.jpg']).items()): try: self.parse_template(file) except ImageError as e: @@ -160,7 +160,7 @@ class DropStatistics: with open(self.csv_file, 'a', newline='', encoding=DropStatistics.CSV_ENCODING) as csv_file: writer = csv.writer(csv_file) - for ts, file in tqdm(load_folder(self.drop_folder(campaign)).items()): + for ts, file in tqdm(load_folder(self.drop_folder(campaign), ext=['.png', '.jpg']).items()): try: rows = list(self.parse_drop(file)) writer.writerows(rows) diff --git a/module/statistics/item.py b/module/statistics/item.py index ceff8a177..f7e578002 100644 --- a/module/statistics/item.py +++ b/module/statistics/item.py @@ -217,13 +217,15 @@ class ItemGrid: self.next_cost_template_index += 1 self.next_cost_template_index = max(self.next_cost_template_index, max_digit + 1) - def match_template(self, image, similarity=None): + def match_template(self, image, similarity=None, mode='all'): """ Match templates, try most frequent hit templates first. Args: image (np.ndarray): similarity (float): + mode (str): 'all' for all templates, may create new templates + 'known' for known templates only, which will skip images named with digit Returns: str: Template name. @@ -234,7 +236,10 @@ class ItemGrid: # Match frequently hit templates first names = np.array(list(self.templates.keys()))[np.argsort(list(self.templates_hit.values()))][::-1] # Match known templates first - names = [name for name in names if not name.isdigit()] + [name for name in names if name.isdigit()] + tmp = [name for name in names if not name.isdigit()] + if mode == 'all': + tmp.extend([name for name in names if name.isdigit()]) + names = tmp for name in names: if color_similar(color1=color, color2=self.colors[name], threshold=30): res = cv2.matchTemplate(image, self.templates[name], cv2.TM_CCOEFF_NORMED) @@ -243,6 +248,8 @@ class ItemGrid: self.templates_hit[name] += 1 return name + if mode == 'known': + return 'unknown' self.next_template_index += 1 name = str(self.next_template_index) logger.info(f'New template: {name}') @@ -334,7 +341,7 @@ class ItemGrid: else: return None - def predict(self, image, name=True, amount=True, cost=False, price=False, tag=False): + def predict(self, image, name=True, amount=True, cost=False, price=False, tag=False, mode='all'): """ Args: image (np.ndarray): @@ -343,6 +350,7 @@ class ItemGrid: cost (bool): If predict the cost to buy item. price (bool): If predict item price. tag (bool): If predict item tag. Tags are like `catchup`, `bonus`. + mode (str): 'all' or 'known' Returns: list[Item]: @@ -354,7 +362,7 @@ class ItemGrid: for item, a in zip(self.items, amount_list): item.amount = a if name: - name_list = [self.match_template(item.image) for item in self.items] + name_list = [self.match_template(item.image, mode=mode) for item in self.items] for item, n in zip(self.items, name_list): item.name = n if cost: