Просмотр исходного кода

fix(Hyakkiyakou): Add nemu_ipc screenshot method #498

ryland 2 лет назад
Родитель
Сommit
ed34dff94d

+ 208 - 208
tasks/AbyssShadows/res/image.json

@@ -1,209 +1,209 @@
-[
-  {
-    "itemName": "ryou_shenshe",
-    "imageName": "res_ryou_shenshe.png",
-    "roiFront": "872,659,62,25",
-    "roiBack": "872,659,62,25",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "阴阳竂->神社"
-  },
-  {
-    "itemName": "ryou_abyss_shadows",
-    "imageName": "res_ryou_abyss_shadows.png",
-    "roiFront": "707,492,110,27",
-    "roiBack": "707,492,110,27",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "神社->狭间暗域"
-  },
-  {
-    "itemName": "abyss_dragon",
-    "imageName": "res_abyss_dragon.png",
-    "roiFront": "227,211,55,151",
-    "roiBack": "190,147,140,283",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "狭间_神龙入口"
-  },
-  {
-    "itemName": "abyss_peacock",
-    "imageName": "res_abyss_peacock.png",
-    "roiFront": "521,152,48,165",
-    "roiBack": "465,104,145,312",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "狭间_孔雀入口"
-  },
-  {
-    "itemName": "abyss_fox",
-    "imageName": "res_abyss_fox.png",
-    "roiFront": "815,174,49,144",
-    "roiBack": "789,130,148,249",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "狭间_白藏主入口"
-  },
-  {
-    "itemName": "abyss_leopard",
-    "imageName": "res_abyss_leopard.png",
-    "roiFront": "1142,166,50,162",
-    "roiBack": "1093,143,138,297",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "狭间_黑豹入口"
-  },
-  {
-    "itemName": "abyss_navigation",
-    "imageName": "res_abyss_navigation.png",
-    "roiFront": "1200,372,50,44",
-    "roiBack": "1200,372,50,44",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "战报"
-  },
-  {
-    "itemName": "abyss_shiki",
-    "imageName": "res_abyss_shiki.png",
-    "roiFront": "1199,462,47,53",
-    "roiBack": "1199,462,47,53",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "式神录"
-  },
-  {
-    "itemName": "abyss_shadows",
-    "imageName": "res_abyss_shadows.png",
-    "roiFront": "711,489,107,38",
-    "roiBack": "711,489,107,38",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "狭间暗域"
-  },
-  {
-    "itemName": "open_abyss_shadows",
-    "imageName": "res_open_abyss_shadows.png",
-    "roiFront": "1133,602,74,58",
-    "roiBack": "1133,602,74,58",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "开启狭间暗域"
-  },
-  {
-    "itemName": "abyss_map",
-    "imageName": "res_abyss_map.png",
-    "roiFront": "306,147,170,48",
-    "roiBack": "306,147,170,48",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "战报页面"
-  },
-  {
-    "itemName": "abyss_map_exit",
-    "imageName": "res_abyss_map_exit.png",
-    "roiFront": "1154,96,32,32",
-    "roiBack": "1154,96,32,32",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "战报退出按钮"
-  },
-  {
-    "itemName": "abyss_fire",
-    "imageName": "res_abyss_fire.png",
-    "roiFront": "1121,605,77,50",
-    "roiBack": "1121,605,77,50",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "挑战按钮"
-  },
-  {
-    "itemName": "abyss_goto_enemy",
-    "imageName": "res_abyss_goto_enemy.png",
-    "roiFront": "1120,610,75,45",
-    "roiBack": "1120,610,75,45",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "前往"
-  },
-  {
-    "itemName": "change_area",
-    "imageName": "res_change_area.png",
-    "roiFront": "993,610,63,61",
-    "roiBack": "993,610,63,61",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "ensure_button",
-    "imageName": "res_ensure_button.png",
-    "roiFront": "672,405,169,55",
-    "roiBack": "672,405,169,55",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "is_attack",
-    "imageName": "res_is_attack.png",
-    "roiFront": "586,62,73,27",
-    "roiBack": "586,62,73,27",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "进攻中"
-  },
-  {
-    "itemName": "peacock_area",
-    "imageName": "res_peacock_area.png",
-    "roiFront": "577,14,127,36",
-    "roiBack": "577,14,127,36",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "leopard_area",
-    "imageName": "res_leopard_area.png",
-    "roiFront": "589,13,104,39",
-    "roiBack": "589,13,104,39",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "黑豹领域"
-  },
-  {
-    "itemName": "fox_area",
-    "imageName": "res_fox_area.png",
-    "roiFront": "581,18,121,29",
-    "roiBack": "581,18,121,29",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "白藏主领域"
-  },
-  {
-    "itemName": "change_area",
-    "imageName": "res_change_area.png",
-    "roiFront": "511,20,27,27",
-    "roiBack": "511,20,27,27",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "更换领域"
-  },
-  {
-    "itemName": "dragon_area",
-    "imageName": "res_dragon_area.png",
-    "roiFront": "584,15,111,34",
-    "roiBack": "584,15,111,34",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "神龙领域"
-  },
-  {
-    "itemName": "wait_to_start",
-    "imageName": "res_wait_to_start.png",
-    "roiFront": "588,64,70,26",
-    "roiBack": "588,64,70,26",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  }
+[
+  {
+    "itemName": "ryou_shenshe",
+    "imageName": "res_ryou_shenshe.png",
+    "roiFront": "872,659,62,25",
+    "roiBack": "872,659,62,25",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "阴阳竂->神社"
+  },
+  {
+    "itemName": "ryou_abyss_shadows",
+    "imageName": "res_ryou_abyss_shadows.png",
+    "roiFront": "707,492,110,27",
+    "roiBack": "707,492,110,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "神社->狭间暗域"
+  },
+  {
+    "itemName": "abyss_dragon",
+    "imageName": "res_abyss_dragon.png",
+    "roiFront": "227,211,55,151",
+    "roiBack": "190,147,140,283",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_神龙入口"
+  },
+  {
+    "itemName": "abyss_peacock",
+    "imageName": "res_abyss_peacock.png",
+    "roiFront": "521,152,48,165",
+    "roiBack": "465,104,145,312",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_孔雀入口"
+  },
+  {
+    "itemName": "abyss_fox",
+    "imageName": "res_abyss_fox.png",
+    "roiFront": "815,174,49,144",
+    "roiBack": "789,130,148,249",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_白藏主入口"
+  },
+  {
+    "itemName": "abyss_leopard",
+    "imageName": "res_abyss_leopard.png",
+    "roiFront": "1142,166,50,162",
+    "roiBack": "1093,143,138,297",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_黑豹入口"
+  },
+  {
+    "itemName": "abyss_navigation",
+    "imageName": "res_abyss_navigation.png",
+    "roiFront": "1200,372,50,44",
+    "roiBack": "1200,372,50,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战报"
+  },
+  {
+    "itemName": "abyss_shiki",
+    "imageName": "res_abyss_shiki.png",
+    "roiFront": "1199,462,47,53",
+    "roiBack": "1199,462,47,53",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "式神录"
+  },
+  {
+    "itemName": "abyss_shadows",
+    "imageName": "res_abyss_shadows.png",
+    "roiFront": "711,489,107,38",
+    "roiBack": "711,489,107,38",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间暗域"
+  },
+  {
+    "itemName": "open_abyss_shadows",
+    "imageName": "res_open_abyss_shadows.png",
+    "roiFront": "1133,602,74,58",
+    "roiBack": "1133,602,74,58",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "开启狭间暗域"
+  },
+  {
+    "itemName": "abyss_map",
+    "imageName": "res_abyss_map.png",
+    "roiFront": "306,147,170,48",
+    "roiBack": "306,147,170,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战报页面"
+  },
+  {
+    "itemName": "abyss_map_exit",
+    "imageName": "res_abyss_map_exit.png",
+    "roiFront": "1154,96,32,32",
+    "roiBack": "1154,96,32,32",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战报退出按钮"
+  },
+  {
+    "itemName": "abyss_fire",
+    "imageName": "res_abyss_fire.png",
+    "roiFront": "1121,605,77,50",
+    "roiBack": "1121,605,77,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "挑战按钮"
+  },
+  {
+    "itemName": "abyss_goto_enemy",
+    "imageName": "res_abyss_goto_enemy.png",
+    "roiFront": "1120,610,75,45",
+    "roiBack": "1120,610,75,45",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "前往"
+  },
+  {
+    "itemName": "change_area",
+    "imageName": "res_change_area.png",
+    "roiFront": "993,610,63,61",
+    "roiBack": "993,610,63,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "ensure_button",
+    "imageName": "res_ensure_button.png",
+    "roiFront": "672,405,169,55",
+    "roiBack": "672,405,169,55",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "is_attack",
+    "imageName": "res_is_attack.png",
+    "roiFront": "586,62,73,27",
+    "roiBack": "586,62,73,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进攻中"
+  },
+  {
+    "itemName": "peacock_area",
+    "imageName": "res_peacock_area.png",
+    "roiFront": "577,14,127,36",
+    "roiBack": "577,14,127,36",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "leopard_area",
+    "imageName": "res_leopard_area.png",
+    "roiFront": "589,13,104,39",
+    "roiBack": "589,13,104,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "黑豹领域"
+  },
+  {
+    "itemName": "fox_area",
+    "imageName": "res_fox_area.png",
+    "roiFront": "581,18,121,29",
+    "roiBack": "581,18,121,29",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "白藏主领域"
+  },
+  {
+    "itemName": "change_area",
+    "imageName": "res_change_area.png",
+    "roiFront": "511,20,27,27",
+    "roiBack": "511,20,27,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "更换领域"
+  },
+  {
+    "itemName": "dragon_area",
+    "imageName": "res_dragon_area.png",
+    "roiFront": "584,15,111,34",
+    "roiBack": "584,15,111,34",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "神龙领域"
+  },
+  {
+    "itemName": "wait_to_start",
+    "imageName": "res_wait_to_start.png",
+    "roiFront": "588,64,70,26",
+    "roiBack": "588,64,70,26",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
 ]

+ 7 - 0
tasks/Hyakkiyakou/config.py

@@ -13,6 +13,10 @@ class InferenceEngine(str, Enum):
     ONNXRUNTIME = 'Onnxruntime'
     TENSORRT = 'TensorRT'
 
+class ScreenshotMethod(str, Enum):
+    WINDOW_BACKGROUND = 'window_background'
+    NEMU_IPC = 'nemu_ipc'
+
 
 class HyakkiyakouConfig(ConfigBase):
     hya_limit_time: Time = Field(default=Time(minute=20), description='hya_limit_time_help')
@@ -52,6 +56,9 @@ class DebugConfig(ConfigBase):
     hya_save_result: bool = Field(default=False, description='hya_save_result_help')
     # 单独的设定截屏间隔, 单位ms
     hya_interval: float = Field(default=300, description='hya_interval_help')
+    # 单独的截屏设置
+    hya_screenshot_method: ScreenshotMethod = Field(default=ScreenshotMethod.WINDOW_BACKGROUND,
+                                                    description='hya_screenshot')
 
 
 class Hyakkiyakou(ConfigBase):

+ 1 - 1
tasks/Hyakkiyakou/script_task.py

@@ -178,7 +178,7 @@ class ScriptTask(GameUi, HyaSlave):
         if self._config.debug_config.hya_show:
             self.debugger.show_start()
         while 1:
-            self.fast_screenshot()
+            self.fast_screenshot(screenshot=self._config.debug_config.hya_screenshot_method)
             if self.appear(self.I_HEND):
                 break
             if not self.appear(self.I_CHECK_RUN):

+ 3 - 2
tasks/Hyakkiyakou/slave/hya_device.py

@@ -7,6 +7,7 @@ from module.base.utils import point2str
 from module.exception import RequestHumanTakeover, GameStuckError
 from tasks.base_task import BaseTask
 
+from tasks.Hyakkiyakou.config import ScreenshotMethod
 
 def image_black(img) -> bool:
     for y, x in [(0, 0), (719, 1279), (719, 0), (0, 1279)]:
@@ -26,10 +27,10 @@ class HyaDevice(BaseTask):
     hya_screenshot_interval = Timer(0.2)  # 300ms
     hya_fs_check_timer = Timer(5 * 60)  # 五分钟跑不完就应该是出问题了
 
-    def fast_screenshot(self):
+    def fast_screenshot(self, screenshot: ScreenshotMethod):
         self.hya_screenshot_interval.wait()
         self.hya_screenshot_interval.reset()
-        self.device.image = self.device.screenshot_window_background()
+        self.device.image = self.device.screenshot_window_background() if screenshot == ScreenshotMethod.WINDOW_BACKGROUND else self.device.screenshot_nemu_ipc()
         if image_black(self.device.image):
             logger.error('Screenshot image is black, try again')
             raise RequestHumanTakeover('Screenshot image is black, try again')

+ 5 - 2
tasks/Hyakkiyakou/slave/hya_slave.py

@@ -226,8 +226,6 @@ class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
             if not self._invite_friend(False):
                 raise RequestHumanTakeover('Invite friend failed')
 
-
-
     def _invite_friend(self, same: bool = True) -> bool:
         if not same:
             logger.info('Invite different server friend')
@@ -264,6 +262,8 @@ class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
     def reset_state(self):
         self.slave_state = [250, 36, 10,
                           HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0]
+
+
 def covert_rgb():
     images_folders: Path = Path(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240614T214216')
     save_folders = images_folders.parent / 'save14'
@@ -275,6 +275,7 @@ def covert_rgb():
         img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
         cv2.imwrite(str(save_folders / file.name), img)
 
+
 def test_predict_res():
     import timeit
     from module.config.config import Config
@@ -295,6 +296,7 @@ def test_predict_res():
     # total time is 36.2ms on my computer /cpu:AMD Ryzen 5 3550H with Radeon Vega Mobile
     # 0.362ms per predict_res
 
+
 def test_predict_bean():
     import timeit
     from module.config.config import Config
@@ -313,6 +315,7 @@ def test_predict_bean():
     # print(f"执行总的时间: {execution_time * 1000} ms")
     # total time is 17.9ms on my computer in 100 times
 
+
 def test_predict_buff():
     import timeit
     from module.config.config import Config