Procházet zdrojové kódy

fix(CostumeCarpBanner):update image of CostumeCarpBanner
-优化匹配方法
-优化鲤鱼旗
-无垢莲台适配更多皮肤
-添加部分翻译

yuyuyuyuyu před 9 měsíci
rodič
revize
1b9a34eb7e

+ 7 - 1
assets/i18n/zh-CN.json

@@ -6,7 +6,13 @@
   "hya_onmyoji_help": "",
   "skill_mode": "技能本模式",
   "costume_shikigami_6": "月下火舞",
-  "costume_shikigami_7": "赤溟幽界"
+  "costume_shikigami_7": "赤溟幽界",
+  "costume_carpbanner_type": "鲤鱼旗皮肤",
+  "costume_carpbanner_default": "吉鲤游风",
+  "costume_carpbanner_1": "无垢莲台",
+  "costume_carpbanner_type_help": "多数结界通用",
+  "costume_battle_10": "流焰蝶舞",
+  "costume_battle_11": "辰烁奇夜"
 }
 
 

+ 16 - 23
module/atom/image.py

@@ -184,42 +184,40 @@ class RuleImage(RuleImageMallResourceMixin):
 
         # 如果指定了 scale_range,自动生成 scales 列表
         if scale_range is not None:
-            if len(scale_range) == 2:
-                # 只有 start, end,默认 step=0.1
-                start, end = scale_range
-                scales = [round(x * 10) / 10 for x in np.arange(start, end + 0.1, 0.1)]
-            else:
-                start, end, step = scale_range
-                scales = [round(x * 10) / 10 for x in np.arange(start, end + step, step)]
+            start, end = scale_range[:2]
+            step = scale_range[2] if len(scale_range) > 2 else 0.1
+            scales = sorted(set(round(x, 1) for x in np.arange(start, end + step, step)))
 
         if scales is None:
             scales = [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
+        else:
+            scales = sorted(set(round(x, 1) for x in scales))
 
         source = self.corp(image)
         mat = self.image
 
         if mat is None or mat.shape[0] == 0 or mat.shape[1] == 0:
             logger.error(f"Template image is invalid: {mat.shape}")
-            return False  # 模板无效,匹配失败
+            return False
+
+        # 预计算模板尺寸
+        mat_h, mat_w = mat.shape[:2]
+        source_h, source_w = source.shape[:2]
 
         best_score = 0
         best_loc = None
         best_scale = 1.0
 
         for scale in scales:
-            try:
-                # 按比例缩放模板
-                scaled_w = int(mat.shape[1] * scale)
-                scaled_h = int(mat.shape[0] * scale)
+            scaled_w = int(mat_w * scale)
+            scaled_h = int(mat_h * scale)
 
-                # 跳过太大或太小的缩放
-                if scaled_w < 10 or scaled_h < 10:
-                    continue
-                if scaled_w > source.shape[1] * 1.5 or scaled_h > source.shape[0] * 1.5:
-                    continue
+            # 跳过无效缩放
+            if scaled_w < 10 or scaled_h < 10:
+                continue
 
+            try:
                 scaled_mat = cv2.resize(mat, (scaled_w, scaled_h))
-
                 res = cv2.matchTemplate(source, scaled_mat, cv2.TM_CCOEFF_NORMED)
                 _, max_val, _, max_loc = cv2.minMaxLoc(res)
 
@@ -234,11 +232,6 @@ class RuleImage(RuleImageMallResourceMixin):
             logger.attr(self.name, f'best scale: {best_scale:.2f}, best score: {best_score:.5f}')
 
         if best_score > threshold and best_loc is not None:
-            # 计算缩放后的模板尺寸
-            scaled_w = int(mat.shape[1] * best_scale)
-            scaled_h = int(mat.shape[0] * best_scale)
-
-            # 设置 roi_front 为匹配位置 + 缩放后的尺寸
             self.roi_front[0] = best_loc[0] + self.roi_back[0]
             self.roi_front[1] = best_loc[1] + self.roi_back[1]
             self.roi_front[2] = scaled_w

+ 1 - 1
tasks/Component/Costume/config.py

@@ -75,7 +75,7 @@ class CostumeConfig(BaseModel):
     # 皮肤配置
     costume_main_type: MainType = Field(default=MainType.COSTUME_MAIN, description='costume_main_type_help')
     costume_realm_type: RealmType = Field(default=RealmType.COSTUME_REALM_DEFAULT, description='costume_realm_type_help')
-    costume_carpbanner_type: CarpBannerType = Field(default=CarpBannerType.COSTUME_CARPBANNER_DEFAULT,description='costume_realm_type_help')
+    costume_carpbanner_type: CarpBannerType = Field(default=CarpBannerType.COSTUME_CARPBANNER_DEFAULT,description='costume_carpbanner_type_help')
     costume_theme_type: ThemeType = Field(default=ThemeType.COSTUME_THEME_DEFAULT, description='costume_theme_type_help')
     costume_shikigami_type: ShikigamiType = Field(default=ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT, description='costume_shikigami_type_help')
     costume_sign_type: SignType = Field(default=SignType.COSTUME_SIGN_DEFAULT, description='costume_sign_type_help')

+ 0 - 2
tasks/Component/Costume/costume_base.py

@@ -48,8 +48,6 @@ carpbanner_costume_model = {
         'I_SHI_CARD': f'I_SHI_CARD_{i}',
         'I_SHI_DEFENSE': f'I_SHI_DEFENSE_{i}',
         'I_SHI_GROWN': f'I_SHI_GROWN_{i}',
-        'I_CARD_EXP': f'I_CARD_EXP_{i}',
-        'I_UTILIZE_EXP': f'I_UTILIZE_EXP_{i}',
     } for i in range(1, 2)
 }
 

+ 3 - 7
tasks/Component/CostumeCarpBanner/assets.py

@@ -12,14 +12,10 @@ class CostumeCarpBannerAssets:
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_1 = RuleImage(roi_front=(602,339,26,37), roi_back=(524,269,181,198), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png")
+	I_SHI_GROWN_1 = RuleImage(roi_front=(572,272,21,33), roi_back=(530,220,202,267), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png")
 	# 结界卡 
-	I_SHI_CARD_1 = RuleImage(roi_front=(887,335,15,35), roi_back=(854,306,87,120), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png")
+	I_SHI_CARD_1 = RuleImage(roi_front=(911,262,20,33), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png")
 	# 防守 
-	I_SHI_DEFENSE_1 = RuleImage(roi_front=(269,335,24,46), roi_back=(200,277,154,166), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png")
-	# 收取经验(没有满的图) 
-	I_CARD_EXP_1 = RuleImage(roi_front=(875,181,57,54), roi_back=(803,111,199,185), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_card_exp_1.png")
-	# 寄养别人的经验 
-	I_UTILIZE_EXP_1 = RuleImage(roi_front=(589,187,58,43), roi_back=(539,144,156,123), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_utilize_exp_1.png")
+	I_SHI_DEFENSE_1 = RuleImage(roi_front=(216,258,22,33), roi_back=(178,209,261,274), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png")
 
 

binární
tasks/Component/CostumeCarpBanner/cb1/cb1_card_exp_1.png


binární
tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png


binární
tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png


binární
tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png


binární
tasks/Component/CostumeCarpBanner/cb1/cb1_utilize_exp_1.png


+ 9 - 27
tasks/Component/CostumeCarpBanner/cb1/image.json

@@ -2,46 +2,28 @@
   {
     "itemName": "shi_grown_1",
     "imageName": "cb1_shi_grown_1.png",
-    "roiFront": "602,339,26,37",
-    "roiBack": "524,269,181,198",
+    "roiFront": "572,272,21,33",
+    "roiBack": "530,220,202,267",
     "method": "Template matching",
-    "threshold": 0.6,
+    "threshold": 0.5,
     "description": "育成"
   },
   {
     "itemName": "shi_card_1",
     "imageName": "cb1_shi_card_1.png",
-    "roiFront": "887,335,15,35",
-    "roiBack": "854,306,87,120",
+    "roiFront": "911,262,20,33",
+    "roiBack": "823,210,252,297",
     "method": "Template matching",
-    "threshold": 0.6,
+    "threshold": 0.5,
     "description": "结界卡"
   },
   {
     "itemName": "shi_defense_1",
     "imageName": "cb1_shi_defense_1.png",
-    "roiFront": "269,335,24,46",
-    "roiBack": "200,277,154,166",
+    "roiFront": "216,258,22,33",
+    "roiBack": "178,209,261,274",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.6,
     "description": "防守"
-  },
-  {
-    "itemName": "card_exp_1",
-    "imageName": "cb1_card_exp_1.png",
-    "roiFront": "875,181,57,54",
-    "roiBack": "803,111,199,185",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "收取经验(没有满的图)"
-  },
-  {
-    "itemName": "utilize_exp_1",
-    "imageName": "cb1_utilize_exp_1.png",
-    "roiFront": "589,187,58,43",
-    "roiBack": "539,144,156,123",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "寄养别人的经验"
   }
 ]