Explorar el Código

feat(Hyakkiyakou): Save progress

ryland hace 2 años
padre
commit
a29a75f529

+ 2 - 0
tasks/Exploration/assets.py

@@ -66,6 +66,8 @@ class ExplorationAssets:
 	I_GET_REWARD = RuleImage(roi_front=(464,231,339,44), roi_back=(464,231,339,44), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_get_reward.png")
 	I_GET_REWARD = RuleImage(roi_front=(464,231,339,44), roi_back=(464,231,339,44), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_get_reward.png")
 	# description 
 	# description 
 	I_RED_CLOSE = RuleImage(roi_front=(1027,129,41,42), roi_back=(1021,121,54,55), threshold=0.6, method="Template matching", file="./tasks/Exploration/res/res_red_close.png")
 	I_RED_CLOSE = RuleImage(roi_front=(1027,129,41,42), roi_back=(1021,121,54,55), threshold=0.6, method="Template matching", file="./tasks/Exploration/res/res_red_close.png")
+	# description 
+	I_E_EXIT_CONFIRM = RuleImage(roi_front=(694,380,163,49), roi_back=(694,380,163,49), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_e_exit_confirm.png")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets

+ 9 - 0
tasks/Exploration/res/image.json

@@ -160,5 +160,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.6,
     "threshold": 0.6,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "e_exit_confirm",
+    "imageName": "res_e_exit_confirm.png",
+    "roiFront": "694,380,163,49",
+    "roiBack": "694,380,163,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
   }
   }
 ]
 ]

BIN
tasks/Exploration/res/res_e_exit_confirm.png


+ 151 - 3
tasks/Hyakkiyakou/utils/exp_test.py

@@ -2,6 +2,7 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 import cv2
 import cv2
+import random
 
 
 from datetime import datetime
 from datetime import datetime
 from pathlib import Path
 from pathlib import Path
@@ -9,10 +10,11 @@ from cached_property import cached_property
 
 
 from module.logger import logger
 from module.logger import logger
 from module.base.timer import Timer
 from module.base.timer import Timer
+from module.atom.click import RuleClick
 
 
 from tasks.Exploration.assets import ExplorationAssets
 from tasks.Exploration.assets import ExplorationAssets
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_main, page_town
+from tasks.GameUi.page import page_main, page_town, page_exploration
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
 from tasks.Script.config_device import ScreenshotMethod, ControlMethod
 from tasks.Script.config_device import ScreenshotMethod, ControlMethod
 from tasks.Component.RightActivity.right_activity import RightActivity
 from tasks.Component.RightActivity.right_activity import RightActivity
@@ -59,7 +61,6 @@ class Step:
 # -----------------------------------------------------------------------
 # -----------------------------------------------------------------------
 
 
 
 
-
 # -----------------------------------------------------------------------
 # -----------------------------------------------------------------------
 
 
 class ExpTest(RightActivity, FastDevice, RestartAssets, ExplorationAssets):
 class ExpTest(RightActivity, FastDevice, RestartAssets, ExplorationAssets):
@@ -82,7 +83,8 @@ class ExpTest(RightActivity, FastDevice, RestartAssets, ExplorationAssets):
         self.ui_click(self.I_LOGIN_SCROOLL_OPEN, self.I_LOGIN_SCROOLL_CLOSE, interval=1)
         self.ui_click(self.I_LOGIN_SCROOLL_OPEN, self.I_LOGIN_SCROOLL_CLOSE, interval=1)
 
 
     def _go(self):
     def _go(self):
-        pass
+        self.ui_get_current_page()
+        self.ui_goto(page_exploration)
 
 
     def run_step(self, step: Step):
     def run_step(self, step: Step):
         logger.hr(f'Running step: {step}', 1)
         logger.hr(f'Running step: {step}', 1)
@@ -149,3 +151,149 @@ class ExpTest(RightActivity, FastDevice, RestartAssets, ExplorationAssets):
         self.run_step(step_6)
         self.run_step(step_6)
         self.run_step(step_7)
         self.run_step(step_7)
         self.run_step(step_8)
         self.run_step(step_8)
+
+    def exp_enter(self, layer: int = 25):
+        w = 188
+        h = 80
+        x_25, y_25 = 1052, 208
+        x_26, y_26 = 1052, 316
+        x_27, y_27 = 1052, 443
+        x_28, y_28 = 1052, 564
+        exp_click_25 = RuleClick(roi_front=(x_25, y_25, w, h), roi_back=(x_25, y_25, w, h), name="exp_click_25")
+        exp_click_26 = RuleClick(roi_front=(x_26, y_26, w, h), roi_back=(x_26, y_26, w, h), name="exp_click_26")
+        exp_click_27 = RuleClick(roi_front=(x_27, y_27, w, h), roi_back=(x_27, y_27, w, h), name="exp_click_27")
+        exp_click_28 = RuleClick(roi_front=(x_28, y_28, w, h), roi_back=(x_28, y_28, w, h), name="exp_click_28")
+        match layer:
+            case 25:
+                exp_click = exp_click_25
+            case 26:
+                exp_click = exp_click_26
+            case 27:
+                exp_click = exp_click_27
+            case 28:
+                exp_click = exp_click_28
+            case _:
+                exp_click = exp_click_28
+        self.ui_click(exp_click, self.I_E_EXPLORATION_CLICK)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_E_AUTO_ROTATE_ON) or self.appear(self.I_E_AUTO_ROTATE_OFF):
+                break
+            if self.appear_then_click(self.I_E_EXPLORATION_CLICK, interval=1):
+                continue
+        logger.info(f'Enter exploration {layer}')
+
+    def exp_exit(self):
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_UI_BACK_RED):
+                break
+            if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
+                continue
+            if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
+                continue
+            if self.appear_then_click(self.I_E_EXIT_CONFIRM, interval=1):
+                continue
+            if self.appear_then_click(self.I_UI_BACK_BLUE, interval=1.5):
+                continue
+        self.ui_click_until_disappear(self.I_UI_BACK_RED, interval=0.5)
+
+    def run_exp_25(self):
+        pos_right = 1270
+        pos_left = 260
+        pos_top = 390
+        pos_bottom = 620
+        pos_level = (pos_top + pos_bottom) / 2
+
+        step_1 = Step('step_1', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_2 = Step('step_2', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_3 = Step('step_3', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_4 = Step('step_4', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_5 = Step('step_5', pos=(pos_right, pos_bottom), time=2.1)
+
+        save_time = 1.6
+        back_1 = Step('back_1', pos=(pos_left, pos_bottom), time=1, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_2 = Step('back_2', pos=(pos_left, pos_top), time=2, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_3 = Step('back_3', pos=(pos_left, pos_top), time=2, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_4 = Step('back_4', pos=(pos_left, pos_bottom), time=2,  save_time=1.6, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_5 = Step('back_5', pos=(pos_left, pos_level), time=save_time, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+
+        self.run_step(step_1)
+        self.run_step(step_2)
+        self.run_step(step_3)
+        self.run_step(step_4)
+        self.run_step(step_5)
+        self.run_step(back_1)
+        self.run_step(back_2)
+        self.run_step(back_3)
+        self.run_step(back_4)
+        self.run_step(back_5)
+
+    def run_exp_26(self):
+        pos_right = 1270
+        pos_left = 260
+        pos_top = 454
+        pos_bottom = 620
+        pos_level = (pos_top + pos_bottom) / 2
+        step_1 = Step('step_1', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_2 = Step('step_2', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_3 = Step('step_3', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_4 = Step('step_4', pos=(pos_right, pos_bottom), time=2.1)
+        self.run_step(step_1)
+        self.run_step(step_2)
+        self.run_step(step_3)
+        self.run_step(step_4)
+
+        back_1 = Step('back_1', pos=(pos_left, pos_bottom), time=1, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_2 = Step('back_2', pos=(pos_left, pos_top), time=2, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_3 = Step('back_3', pos=(pos_left, pos_top), time=2, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_4 = Step('back_4', pos=(pos_left, pos_bottom), time=2, save_time=1.6, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_5 = Step('back_5', pos=(pos_left, pos_level), time=1.7, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+
+        self.run_step(back_1)
+        self.run_step(back_2)
+        self.run_step(back_3)
+        self.run_step(back_4)
+        self.run_step(back_5)
+
+    def run_exp_27(self):
+        pos_right = 1270
+        pos_left = 260
+        pos_top = 510
+        pos_bottom = 620
+        pos_level = (pos_top + pos_bottom) / 2
+        step_1 = Step('step_1', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.1)
+        step_2 = Step('step_2', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.3)
+        step_3 = Step('step_3', pos=(pos_right, random.randint(pos_top, pos_bottom)), time=2.5)
+        step_4 = Step('step_4', pos=(pos_right, pos_bottom), time=2.9)
+        self.run_step(step_1)
+        self.run_step(step_2)
+        self.run_step(step_3)
+        self.run_step(step_4)
+
+        back_1 = Step('back_1', pos=(pos_left, pos_bottom), time=1, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_2 = Step('back_2', pos=(pos_left, pos_top), time=2, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_3 = Step('back_3', pos=(pos_left, pos_top), time=2, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_4 = Step('back_4', pos=(pos_left, pos_bottom), time=2, save_time=1.6, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+        back_5 = Step('back_5', pos=(pos_left, pos_level), time=1.7, save_img=True,
+                      save_roi=(random.randint(100, 540), 80))
+
+        self.run_step(back_1)
+        self.run_step(back_2)
+        self.run_step(back_3)
+        self.run_step(back_4)
+        self.run_step(back_5)

+ 28 - 12
tasks/Hyakkiyakou/utils/video2images.py

@@ -43,9 +43,10 @@ class TransformVideo(HyakkiyakouAssets):
         else:
         else:
             self.parse_one(video, save_path)
             self.parse_one(video, save_path)
 
 
-    def parse_one(self, video: Path, save_path: Path = None):
+    def parse_one(self, video: Path, save_path: Path = None, mode: int = 2):
         """
         """
         单次解析一个视频
         单次解析一个视频
+        @param mode: 0:左边 1:右边 2: 两边
         @param video:
         @param video:
         @param save_path:
         @param save_path:
         @return:
         @return:
@@ -73,6 +74,12 @@ class TransformVideo(HyakkiyakouAssets):
             ret, frame = cap.read()
             ret, frame = cap.read()
             if not ret:
             if not ret:
                 break
                 break
+
+                # 抽帧
+            count_frame += 1
+            if count_frame % frame_skip != 0:
+                continue
+
             w, h, _ = frame.shape
             w, h, _ = frame.shape
             if h == 720 and w == 1280:
             if h == 720 and w == 1280:
                 pass
                 pass
@@ -81,10 +88,6 @@ class TransformVideo(HyakkiyakouAssets):
             elif w != 1280 and h != 720:
             elif w != 1280 and h != 720:
                 frame = cv2.resize(frame, (1280, 720))
                 frame = cv2.resize(frame, (1280, 720))
             frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
             frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
-            # 抽帧
-            count_frame += 1
-            if count_frame % frame_skip != 0:
-                continue
 
 
             # 检查是否是百鬼夜行中
             # 检查是否是百鬼夜行中
             # if not self.I_CHECK_RUN.match(frame, threshold=0.5):
             # if not self.I_CHECK_RUN.match(frame, threshold=0.5):
@@ -92,17 +95,30 @@ class TransformVideo(HyakkiyakouAssets):
             if not self.change_channel:
             if not self.change_channel:
                 frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
                 frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
             index_frame += 1
             index_frame += 1
-            cv2.imwrite(str(save_path / f'{datetime_now}_{index_frame:05d}.png'), frame)
-            # cv2.imshow('frame', frame)
-            # cv2.waitKey(100)
-            # cv2.destroyAllWindows()
+
+            match mode:
+                case 0:
+                    img_a = frame[80:, 0:640]
+                    img_b = None
+                case 1:
+                    img_a = None
+                    img_b = frame[80:, 640:1280]
+                case 2:
+                    img_a = frame[80:, 0:640]
+                    img_b = frame[80:, 640:1280]
+                case _:
+                    raise ValueError('mode must be 0, 1, or 2')
+            if img_a is not None:
+                cv2.imwrite(str(save_path / f'{datetime_now}_{index_frame:05d}a.png'), img_a)
+            if img_b is not None:
+                cv2.imwrite(str(save_path / f'{datetime_now}_{index_frame:05d}b.png'), img_b)
 
 
         cap.release()
         cap.release()
         logger.info(f'{video} done')
         logger.info(f'{video} done')
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    VIDEO = 'F:/videos/444592487.mp4'
+    VIDEO = r'C:\Users\Ryland\Downloads\202404021234_ssr_021_a.mp4'
     # SAVE_PATH = 'D:/Project/Hyakkiyakou/OnmyojiAutoScript-hyakkiyakou/temp/sources_images'
     # SAVE_PATH = 'D:/Project/Hyakkiyakou/OnmyojiAutoScript-hyakkiyakou/temp/sources_images'
-    t = TransformVideo(interval=0.1)
-    t.parse_one(VIDEO)
+    t = TransformVideo(change_channel=True, interval=0.1)
+    t.parse_one(VIDEO, mode=1)