Kaynağa Gözat

fix(device): Skip processing for non-landscape screenshots
- add a simple 1280x720 screenshot shape check
- skip login and harvest processing until the screen is landscape
- remove the redundant template-size guard

neptine 2 ay önce
ebeveyn
işleme
01f24bdba5
3 değiştirilmiş dosya ile 10 ekleme ve 5 silme
  1. 0 5
      module/atom/image.py
  2. 3 0
      module/device/screenshot.py
  3. 7 0
      tasks/Restart/login.py

+ 0 - 5
module/atom/image.py

@@ -158,11 +158,6 @@ class RuleImage(RuleImageMallResourceMixin):
             logger.error(f"Template image is invalid: {mat.shape}")
             return False  # 模板无效,匹配失败
 
-        # 截图竖屏(宽<高, 登录阶段游戏尚未横屏)或roiBack越界时, 裁剪图可能小于模板,
-        # 直接返回False防止matchTemplate断言崩溃, 横屏后自动恢复
-        if source.shape[0] < mat.shape[0] or source.shape[1] < mat.shape[1]:
-            return False
-
         res = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
         min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)  # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标
         if self.debug_mode:

+ 3 - 0
module/device/screenshot.py

@@ -232,6 +232,9 @@ class Screenshot(Adb, DroidCast, Scrcpy, Window, NemuIpc):
                 logger.critical('Please set emulator resolution to 1280x720')
                 raise RequestHumanTakeover
 
+    def check_screen_size_sample(self):
+        return self.image.shape  == (720, 1280, 3)
+
     def check_screen_black(self):
         if self._screen_black_checked:
             return True

+ 7 - 0
tasks/Restart/login.py

@@ -40,6 +40,10 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
                 orientation_timer.reset()
 
             self.screenshot()
+            # https://github.com/runhey/OnmyojiAutoScript/pull/1761
+            if not self.device.check_screen_size_sample():
+                continue
+
             # 取消继续战斗
             if self.appear_then_click(self.I_CANCEL_BATTLE, interval=0.8):
                 logger.info('Cancel continue battle')
@@ -171,6 +175,9 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
         courtyard_affairs_done = False  # 庭院事务只执行一次
         while 1:
             self.screenshot()
+            # https://github.com/runhey/OnmyojiAutoScript/pull/1761
+            if not self.device.check_screen_size_sample():
+                continue
 
             # 点击'获得奖励'
             if self.ui_reward_appear_click():