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

perf(Hyakkiyakou) generate image

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

+ 14 - 3
tasks/Hyakkiyakou/assets.py

@@ -10,11 +10,16 @@ from module.atom.list import RuleList
 class HyakkiyakouAssets: 
 
 
+	# Click Rule Assets
+	# description 
+	C_CLICK = RuleClick(roi_front=(26,250,33,100), roi_back=(26,250,33,100), name="click")
+
+
 	# Image Rule Assets
 	# 缘结之庭 
 	I_TPAGE_1 = RuleImage(roi_front=(238,504,221,123), roi_back=(121,480,950,166), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_1.png")
 	# 本丸御殿 
-	I_TPAGE_2 = RuleImage(roi_front=(491,506,231,120), roi_back=(132,479,933,171), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_2.png")
+	I_TPAGE_2 = RuleImage(roi_front=(411,506,231,120), roi_back=(132,479,933,171), threshold=0.5, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_2.png")
 	# 之境 
 	I_TPAGE_3 = RuleImage(roi_front=(748,504,240,118), roi_back=(125,482,937,166), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_3.png")
 	# 鲸歌潜岸 
@@ -32,15 +37,21 @@ class HyakkiyakouAssets:
 	# description 
 	I_TCHECK_4 = RuleImage(roi_front=(7,108,100,332), roi_back=(0,101,120,347), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_4.png")
 	# description 
-	I_TCHECK_5 = RuleImage(roi_front=(23,111,100,355), roi_back=(9,99,134,378), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_5.png")
+	I_TCHECK_5 = RuleImage(roi_front=(132,28,77,103), roi_back=(94,13,152,234), threshold=0.4, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_5.png")
 	# description 
 	I_TCHECK_6 = RuleImage(roi_front=(9,107,100,350), roi_back=(3,97,113,369), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_6.png")
 	# description 
 	I_SWITCH_BACKGROUND = RuleImage(roi_front=(992,649,105,36), roi_back=(969,627,152,72), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_switch_background.png")
+	# description 
+	I_TCHECK_22 = RuleImage(roi_front=(14,150,100,100), roi_back=(5,139,124,127), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_22.png")
+	# description 
+	I_TCHECK_32 = RuleImage(roi_front=(35,175,100,100), roi_back=(26,155,123,141), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_32.png")
 
 
 	# Swipe Rule Assets
 	# description 
-	S_TSWIPE = RuleSwipe(roi_front=(612,527,21,91), roi_back=(359,519,23,100), mode="default", name="tswipe")
+	S_TSWIPE = RuleSwipe(roi_front=(421,521,21,91), roi_back=(273,516,23,100), mode="default", name="tswipe")
+	# description 
+	S_TBACK = RuleSwipe(roi_front=(259,515,21,100), roi_back=(993,521,22,100), mode="default", name="tback")
 
 

+ 82 - 13
tasks/Hyakkiyakou/generate.py

@@ -4,6 +4,7 @@
 import cv2
 from time import time, sleep
 from random import randint
+from pathlib import Path
 from cached_property import cached_property
 
 from module.daemon.benchmark import Benchmark
@@ -20,8 +21,10 @@ class ScriptTask(Benchmark, HyakkiyakouAssets):
                            roi_back=(667, 147, 461, 427),
                            mode="default",
                            name="Left Swipe")
+    hero_name = ''
 
     def run_simple(self, hero_name: str='test'):
+        ScriptTask.hero_name = hero_name
         self.add_one_video(hero_name, index=0)
 
     def run(self, hero_name: str = 'test'):
@@ -29,13 +32,16 @@ class ScriptTask(Benchmark, HyakkiyakouAssets):
         :param hero_name: 你式神的名字
         :return:
         """
+        ScriptTask.hero_name = hero_name
         self.screenshot_benchmark()
         self.record_one(self.I_TPAGE_1, self.I_TCHECK_1, hero_name, index=1)
         self.record_one(self.I_TPAGE_2, self.I_TCHECK_2, hero_name, index=2)
         self.record_one(self.I_TPAGE_3, self.I_TCHECK_3, hero_name, index=3)
         self.record_one(self.I_TPAGE_4, self.I_TCHECK_4, hero_name, index=4)
-        self.record_one(self.I_TPAGE_5, self.I_TCHECK_5, hero_name, index=5)
         self.record_one(self.I_TPAGE_6, self.I_TCHECK_6, hero_name, index=6)
+        self.record_one(self.I_TPAGE_5, self.I_TCHECK_5, hero_name, index=5)
+
+        self.back_one()
 
     def screenshot_benchmark(self):
         self.config.model.script.device.screenshot_method = ScreenshotMethod.WINDOW_BACKGROUND
@@ -44,7 +50,9 @@ class ScriptTask(Benchmark, HyakkiyakouAssets):
 
     @classmethod
     def video(cls, name: str = 'test'):
-        return cv2.VideoWriter(f'./log/tmp/{name}_{int(time() * 1000)}.avi',
+        path = f'./log/tmp/{ScriptTask.hero_name}'
+        Path(path).mkdir(parents=True, exist_ok=True)
+        return cv2.VideoWriter(f'{path}/{name}@{int(time() * 1000)}.avi',
                                cv2.VideoWriter_fourcc(*'XVID'),
                                10,  # fps
                                (1280, 720),  # frame size
@@ -54,46 +62,107 @@ class ScriptTask(Benchmark, HyakkiyakouAssets):
         self.screenshot()
         video.write(self.device.image)
         # 竖直方向在240-480之间随机滑动
-        self.device.swipe(p1=(640, 240 + randint(0, 240)), p2=(640 - 64, 240 + randint(0, 240)),
+        self.device.swipe(p1=(640, 690 + randint(0, 28)), p2=(640 - 64, 690 + randint(0, 28)),
                           distance_check=False)
         # self.device.swipe(p1=(640, 360), p2=(640-64, 360))
-        sleep(0.5)
+        sleep(0.05)
 
     def add_one_video(self, name: str, index: int = 0):
-        video = ScriptTask.video(name=f'{name}_{index}')
+        video = ScriptTask.video(name=f'{name}@{index}')
         for _ in range(20):
             self.add_one_frame(video)
         video.release()
         cv2.destroyAllWindows()
 
     def record_one(self, tpage: RuleImage, tcheck: RuleImage, name: str, index: int = 0):
-        logger.info(f'开始录制第{index}个视频')
+        logger.hr(f'开始录制第{index}个视频')
+        skip_swipe_time = 2
         while 1:
             self.screenshot()
-            if self.appear(tpage):
-                self.ui_click(tpage, tcheck)
-                break
             self.appear_then_click(self.I_SWITCH_BACKGROUND, interval=4)
+            sleep(0.5)
+            if self.appear(tpage) or self.appear(tcheck):
+                # self.ui_click(tpage, tcheck)
+                click_count = 0
+                while 1:
+                    self.screenshot()
+                    if self.appear(tcheck):
+                        break
+                    if tcheck == self.I_TCHECK_2 and self.appear(self.I_TCHECK_22):
+                        logger.warning('I_TCHECK_22')
+                        break
+                    if tcheck == self.I_TCHECK_3 and self.appear(self.I_TCHECK_32):
+                        logger.warning('I_TCHECK_32')
+                        break
+                    if click_count > 5:
+                        logger.warning('已经点击背景五次了')
+                        break
+
+                    if self.appear_then_click(tpage, interval=2):
+                        click_count += 1
+                        continue
+                break
+
+            sleep(0.5)
+            if skip_swipe_time > 0:
+                skip_swipe_time -= 1
+                continue
+            self.swipe(self.S_TSWIPE, interval=1.5)
             sleep(1)
-            self.swipe(self.S_TSWIPE, interval=2.5)
         while 1:
             self.screenshot()
             if not self.appear(tpage):
                 break
             if self.appear_then_click(tcheck, interval=1.2):
                 continue
+            if self.click(self.C_CLICK, interval=4):
+                continue
+            if self.appear_then_click(self.I_TCHECK_22, interval=2):
+                continue
+            if self.appear_then_click(self.I_TCHECK_32, interval=2):
+                continue
 
         logger.info(f'已进入第{index}个背景')
+        sleep(0.5)
         self.add_one_video(name, index=index)
 
+    def back_one(self):
+        while 1:
+            self.screenshot()
+            if (self.appear(self.I_TPAGE_5)
+                    or self.appear(self.I_TPAGE_6)
+                    or self.appear(self.I_TCHECK_4)):
+                break
+            if self.appear_then_click(self.I_SWITCH_BACKGROUND, interval=1.2):
+                continue
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_TPAGE_1):
+                break
+            if self.swipe(self.S_TBACK, interval=2):
+                sleep(1.5)
+                continue
+        self.ui_click(self.I_TPAGE_1, self.I_TCHECK_1)
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_TPAGE_1):
+                break
+            if self.appear_then_click(self.I_TCHECK_1, interval=1.2):
+                continue
+
+
+
+
+
 
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
 
-    c = Config('test')
+    c = Config('oas1')
     d = Device(c)
     t = ScriptTask(c, d)
-    HERO_NAME = 'test'
-    # t.run(HERO_NAME)
+    HERO_NAME = 'sp_009'
     t.run_simple(HERO_NAME)
+    t.run(HERO_NAME)
+

+ 8 - 0
tasks/Hyakkiyakou/train/click.json

@@ -0,0 +1,8 @@
+[
+  {
+    "itemName": "click",
+    "roiFront": "26,250,33,100",
+    "roiBack": "26,250,33,100",
+    "description": "description"
+  }
+]

+ 24 - 6
tasks/Hyakkiyakou/train/image.json

@@ -11,10 +11,10 @@
   {
     "itemName": "tpage_2",
     "imageName": "train_tpage_2.png",
-    "roiFront": "491,506,231,120",
+    "roiFront": "411,506,231,120",
     "roiBack": "132,479,933,171",
     "method": "Template matching",
-    "threshold": 0.7,
+    "threshold": 0.5,
     "description": "本丸御殿"
   },
   {
@@ -23,7 +23,7 @@
     "roiFront": "748,504,240,118",
     "roiBack": "125,482,937,166",
     "method": "Template matching",
-    "threshold": 0.7,
+    "threshold": 0.8,
     "description": "之境"
   },
   {
@@ -92,10 +92,10 @@
   {
     "itemName": "tcheck_5",
     "imageName": "train_tcheck_5.png",
-    "roiFront": "23,111,100,355",
-    "roiBack": "9,99,134,378",
+    "roiFront": "132,28,77,103",
+    "roiBack": "94,13,152,234",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.4,
     "description": "description"
   },
   {
@@ -115,5 +115,23 @@
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"
+  },
+  {
+    "itemName": "tcheck_22",
+    "imageName": "train_tcheck_22.png",
+    "roiFront": "14,150,100,100",
+    "roiBack": "5,139,124,127",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tcheck_32",
+    "imageName": "train_tcheck_32.png",
+    "roiFront": "35,175,100,100",
+    "roiBack": "26,155,123,141",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "description"
   }
 ]

+ 9 - 2
tasks/Hyakkiyakou/train/swipe.json

@@ -1,8 +1,15 @@
 [
   {
     "itemName": "tswipe",
-    "roiFront": "612,527,21,91",
-    "roiBack": "359,519,23,100",
+    "roiFront": "421,521,21,91",
+    "roiBack": "273,516,23,100",
+    "mode": "default",
+    "description": "description"
+  },
+  {
+    "itemName": "tback",
+    "roiFront": "259,515,21,100",
+    "roiBack": "993,521,22,100",
     "mode": "default",
     "description": "description"
   }

BIN
tasks/Hyakkiyakou/train/train_tcheck_22.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_32.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_5.png


BIN
tasks/Hyakkiyakou/train/train_tpage_2.png