Преглед изворни кода

feat(development): Add assets_test.py

ryland пре 2 година
родитељ
комит
74902288e6

+ 36 - 0
dev_tools/assets_test.py

@@ -0,0 +1,36 @@
+import cv2
+import numpy as np
+
+from numpy import float32, int32, uint8, fromfile
+from pathlib import Path
+
+from module.logger import logger
+from module.atom.image import RuleImage
+from module.atom.ocr import RuleOcr
+
+
+def load_image(file: str):
+    img = cv2.imdecode(fromfile(file, dtype=uint8), -1)
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+
+    height, width, channels = img.shape
+    if height != 720 or width != 1280:
+        logger.error(f'Image size is {height}x{width}, not 720x1280')
+        return None
+    return img
+
+
+def detect_image(file: str, targe: RuleImage) -> bool:
+    img = load_image(file)
+    return targe.match(img)
+
+
+# 图片文件路径 可以是相对路径
+IMAGE_FILE = './log/error/1704971960417/2024-01-11_19-19-20-403213.png'
+if __name__ == '__main__':
+    from tasks.KekkaiActivation.assets import KekkaiActivationAssets
+    targe = KekkaiActivationAssets.I_A_HARVEST_FISH_6
+    print(detect_image(IMAGE_FILE, targe))
+
+
+

+ 1 - 0
module/atom/image.py

@@ -98,6 +98,7 @@ class RuleImage:
         :return:
         """
         x, y, w, h = self.roi_back
+        x, y, w, h = int(x), int(y), int(w), int(h)
         return image[y:y + h, x:x + w]
 
 

+ 1 - 1
module/ocr/sub_ocr.py

@@ -158,7 +158,7 @@ class Duration(Single):
     def after_process(self, result):
         result = super().after_process(result)
         result = result.replace('I', '1').replace('D', '0').replace('S', '5')
-        result = result.replace('B', '8').replace(':', ':')
+        result = result.replace('B', '8').replace(':', ':').replace(':', ':').replace(' ', '')
         return result
 
     @staticmethod

+ 1 - 1
tasks/KekkaiActivation/script_task.py

@@ -104,7 +104,7 @@ class ScriptTask(KU, KekkaiActivationAssets):
             # 不稳定太,等待动画结束
             if not card_status and not card_effect:
                 # 黄色的 ”激活“
-                if self.appear(self.I_A_ACTIVATE_YELLOW, threshold=0.99):
+                if self.appear(self.I_A_ACTIVATE_YELLOW, threshold=0.95):
                     continue
             # 如果这张卡生效着,在使用中
             if card_status and card_effect:

+ 2 - 2
tasks/Restart/login.py

@@ -34,7 +34,7 @@ class LoginHandler(BaseTask, RestartAssets):
             self.screenshot()
 
             # 确认进入庭院
-            if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2, threshold=0.85):
+            if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2, threshold=0.9):
                 logger.info('Open scroll')
                 continue
             if self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.2):
@@ -102,7 +102,7 @@ class LoginHandler(BaseTask, RestartAssets):
                 continue
 
         logger.critical('Login failed more than 3')
-        logger.critical('Azur Lane server may be under maintenance, or you may lost network connection')
+        logger.critical('Onmyoji server may be under maintenance, or you may lost network connection')
         raise RequestHumanTakeover
 
 

+ 3 - 2
tasks/Restart/script_task.py

@@ -50,11 +50,12 @@ if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
 
-    config = Config('oas2')
+    config = Config('oas1')
     device = Device(config)
     task = ScriptTask(config, device)
     task.app_restart()
-
+    # task.screenshot()
+    # print(task.appear_then_click(task.I_LOGIN_SCROOLL_CLOSE, threshold=0.9))