소스 검색

feat(Hyakkiyakou): Record to video

huangrunheng 2 년 전
부모
커밋
7dfc3559e5

+ 35 - 1
tasks/Hyakkiyakou/assets.py

@@ -8,5 +8,39 @@ from module.atom.list import RuleList
 # This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class HyakkiyakouAssets: 
-	pass
+
+
+	# 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_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")
+	# 鲸歌潜岸 
+	I_TPAGE_4 = RuleImage(roi_front=(281,507,233,120), roi_back=(124,484,933,163), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_4.png")
+	# 杨帆远航 
+	I_TPAGE_5 = RuleImage(roi_front=(539,506,238,120), roi_back=(130,483,940,166), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_5.png")
+	# 繁影留住 
+	I_TPAGE_6 = RuleImage(roi_front=(801,505,232,118), roi_back=(128,493,937,153), threshold=0.7, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tpage_6.png")
+	# description 
+	I_TCHECK_1 = RuleImage(roi_front=(19,246,100,100), roi_back=(2,218,135,215), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_1.png")
+	# description 
+	I_TCHECK_2 = RuleImage(roi_front=(9,216,157,226), roi_back=(0,197,186,263), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_2.png")
+	# description 
+	I_TCHECK_3 = RuleImage(roi_front=(5,126,138,299), roi_back=(2,110,147,345), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_tcheck_3.png")
+	# 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")
+	# 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")
+
+
+	# Swipe Rule Assets
+	# description 
+	S_TSWIPE = RuleSwipe(roi_front=(612,527,21,91), roi_back=(359,519,23,100), mode="default", name="tswipe")
+
 

+ 99 - 0
tasks/Hyakkiyakou/generate.py

@@ -0,0 +1,99 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import cv2
+from time import time, sleep
+from random import randint
+from cached_property import cached_property
+
+from module.daemon.benchmark import Benchmark
+from module.atom.swipe import RuleSwipe
+from module.atom.image import RuleImage
+from module.logger import logger
+
+from tasks.Script.config_device import ScreenshotMethod, ControlMethod
+from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
+
+
+class ScriptTask(Benchmark, HyakkiyakouAssets):
+    Left_Swipe = RuleSwipe(roi_front=(122, 155, 480, 426),
+                           roi_back=(667, 147, 461, 427),
+                           mode="default",
+                           name="Left Swipe")
+
+    def run_simple(self, hero_name: str='test'):
+        self.add_one_video(hero_name, index=0)
+
+    def run(self, hero_name: str = 'test'):
+        """
+        :param hero_name: 你式神的名字
+        :return:
+        """
+        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)
+
+    def screenshot_benchmark(self):
+        self.config.model.script.device.screenshot_method = ScreenshotMethod.WINDOW_BACKGROUND
+        # self.config.model.script.device.control_method = ControlMethod.WINDOW_MESSAGE
+        self.benchmark([ScreenshotMethod.WINDOW_BACKGROUND])
+
+    @classmethod
+    def video(cls, name: str = 'test'):
+        return cv2.VideoWriter(f'./log/tmp/{name}_{int(time() * 1000)}.avi',
+                               cv2.VideoWriter_fourcc(*'XVID'),
+                               10,  # fps
+                               (1280, 720),  # frame size
+                               )
+
+    def add_one_frame(self, video):
+        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)),
+                          distance_check=False)
+        # self.device.swipe(p1=(640, 360), p2=(640-64, 360))
+        sleep(0.5)
+
+    def add_one_video(self, name: str, index: int = 0):
+        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}个视频')
+        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(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
+
+        logger.info(f'已进入第{index}个背景')
+        self.add_one_video(name, index=index)
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('test')
+    d = Device(c)
+    t = ScriptTask(c, d)
+    HERO_NAME = 'test'
+    # t.run(HERO_NAME)
+    t.run_simple(HERO_NAME)

+ 119 - 0
tasks/Hyakkiyakou/train/image.json

@@ -0,0 +1,119 @@
+[
+  {
+    "itemName": "tpage_1",
+    "imageName": "train_tpage_1.png",
+    "roiFront": "238,504,221,123",
+    "roiBack": "121,480,950,166",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "缘结之庭"
+  },
+  {
+    "itemName": "tpage_2",
+    "imageName": "train_tpage_2.png",
+    "roiFront": "491,506,231,120",
+    "roiBack": "132,479,933,171",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "本丸御殿"
+  },
+  {
+    "itemName": "tpage_3",
+    "imageName": "train_tpage_3.png",
+    "roiFront": "748,504,240,118",
+    "roiBack": "125,482,937,166",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "之境"
+  },
+  {
+    "itemName": "tpage_4",
+    "imageName": "train_tpage_4.png",
+    "roiFront": "281,507,233,120",
+    "roiBack": "124,484,933,163",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "鲸歌潜岸"
+  },
+  {
+    "itemName": "tpage_5",
+    "imageName": "train_tpage_5.png",
+    "roiFront": "539,506,238,120",
+    "roiBack": "130,483,940,166",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "杨帆远航"
+  },
+  {
+    "itemName": "tpage_6",
+    "imageName": "train_tpage_6.png",
+    "roiFront": "801,505,232,118",
+    "roiBack": "128,493,937,153",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "繁影留住"
+  },
+  {
+    "itemName": "tcheck_1",
+    "imageName": "train_tcheck_1.png",
+    "roiFront": "19,246,100,100",
+    "roiBack": "2,218,135,215",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tcheck_2",
+    "imageName": "train_tcheck_2.png",
+    "roiFront": "9,216,157,226",
+    "roiBack": "0,197,186,263",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tcheck_3",
+    "imageName": "train_tcheck_3.png",
+    "roiFront": "5,126,138,299",
+    "roiBack": "2,110,147,345",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tcheck_4",
+    "imageName": "train_tcheck_4.png",
+    "roiFront": "7,108,100,332",
+    "roiBack": "0,101,120,347",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tcheck_5",
+    "imageName": "train_tcheck_5.png",
+    "roiFront": "23,111,100,355",
+    "roiBack": "9,99,134,378",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tcheck_6",
+    "imageName": "train_tcheck_6.png",
+    "roiFront": "9,107,100,350",
+    "roiBack": "3,97,113,369",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "switch_background",
+    "imageName": "train_switch_background.png",
+    "roiFront": "992,649,105,36",
+    "roiBack": "969,627,152,72",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "description"
+  }
+]

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

@@ -0,0 +1,9 @@
+[
+  {
+    "itemName": "tswipe",
+    "roiFront": "612,527,21,91",
+    "roiBack": "359,519,23,100",
+    "mode": "default",
+    "description": "description"
+  }
+]

BIN
tasks/Hyakkiyakou/train/train_switch_background.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_1.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_2.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_3.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_4.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_5.png


BIN
tasks/Hyakkiyakou/train/train_tcheck_6.png


BIN
tasks/Hyakkiyakou/train/train_tpage_1.png


BIN
tasks/Hyakkiyakou/train/train_tpage_2.png


BIN
tasks/Hyakkiyakou/train/train_tpage_3.png


BIN
tasks/Hyakkiyakou/train/train_tpage_4.png


BIN
tasks/Hyakkiyakou/train/train_tpage_5.png


BIN
tasks/Hyakkiyakou/train/train_tpage_6.png