Răsfoiți Sursa

feat(Hyakkiyakou): video2images

ryland 2 ani în urmă
părinte
comite
051a0ca6da

+ 1 - 1
tasks/CollectiveMissions/assets.py

@@ -56,7 +56,7 @@ class CollectiveMissionsAssets:
 	# Ocr-description 
 	# Ocr-description 
 	O_CM_6 = RuleOcr(roi=(1002,133,91,42), area=(1002,133,91,42), mode="Single", method="Default", keyword="", name="cm_6")
 	O_CM_6 = RuleOcr(roi=(1002,133,91,42), area=(1002,133,91,42), mode="Single", method="Default", keyword="", name="cm_6")
 	# 记录已完成的数量 
 	# 记录已完成的数量 
-	O_CM_NUMBER = RuleOcr(roi=(1105,564,60,28), area=(1105,564,60,28), mode="DigitCounter", method="Default", keyword="", name="cm_number")
+	O_CM_NUMBER = RuleOcr(roi=(1097,564,58,28), area=(1097,564,58,28), mode="DigitCounter", method="Default", keyword="", name="cm_number")
 	# 材料的数量 
 	# 材料的数量 
 	O_CM_1_MATTER = RuleOcr(roi=(427,172,100,27), area=(427,172,100,27), mode="DigitCounter", method="Default", keyword="", name="cm_1_matter")
 	O_CM_1_MATTER = RuleOcr(roi=(427,172,100,27), area=(427,172,100,27), mode="DigitCounter", method="Default", keyword="", name="cm_1_matter")
 	# Ocr-description 
 	# Ocr-description 

+ 2 - 0
tasks/Hyakkiyakou/assets.py

@@ -46,6 +46,8 @@ class HyakkiyakouAssets:
 	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")
 	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 
 	# 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")
 	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")
+	# 检查是否在砸豆子 
+	I_CHECK_RUN = RuleImage(roi_front=(95,598,92,45), roi_back=(68,578,143,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/train/train_check_run.png")
 
 
 
 
 	# Swipe Rule Assets
 	# Swipe Rule Assets

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

@@ -133,5 +133,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.7,
     "threshold": 0.7,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "check_run",
+    "imageName": "train_check_run.png",
+    "roiFront": "95,598,92,45",
+    "roiBack": "68,578,143,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "检查是否在砸豆子"
   }
   }
 ]
 ]

BIN
tasks/Hyakkiyakou/train/train_check_run.png


+ 96 - 0
tasks/Hyakkiyakou/utils/video2images.py

@@ -0,0 +1,96 @@
+import cv2
+
+from datetime import datetime
+from pathlib import Path
+
+from module.logger import logger
+
+from tasks.base_task import BaseTask
+from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
+
+
+class TransformVideo(HyakkiyakouAssets):
+    def __init__(self, change_channel: bool = False, interval: float = 2):
+        """
+
+        @param interval: 视频帧间隔,默认2
+        @param change_channel: 修改视频通道数,默认False
+        """
+        self.change_channel = change_channel
+        self.interval = interval
+
+    def run(self, video: str | Path, save_path: str | Path):
+        """
+
+        @param video: 视频的路径,可以是单个视频也可以是一个文件夹
+        @param save_path: 保存的路径
+        @return:
+        """
+        if isinstance(video, str):
+            video = Path(video)
+        if not isinstance(video, Path):
+            logger.error(f'{video} is not a valid path')
+            return
+        if isinstance(save_path, str):
+            save_path = Path(save_path)
+        if not isinstance(save_path, Path):
+            logger.error(f'{save_path} is not a valid path')
+            return
+        save_path.mkdir(parents=True, exist_ok=True)
+        if video.is_dir():
+            for video_file in video.iterdir():
+                self.parse_one(video_file, save_path)
+        else:
+            self.parse_one(video, save_path)
+
+    def parse_one(self, video: Path, save_path: Path):
+        """
+        单次解析一个视频
+        @param video:
+        @param save_path:
+        @return:
+        """
+        # 获取时间戳的str形式,用来命名图片
+        datetime_now = datetime.now().strftime('%Y%m%dT%H%M%S')
+        logger.info(f'Start transform video {video}')
+
+        cap = cv2.VideoCapture(str(video))
+        if not cap.isOpened():
+            logger.error(f'{video} open failed')
+            return
+        fps = cap.get(cv2.CAP_PROP_FPS)
+        frame_skip = int(fps * self.interval)
+        count_frame = 0  # 抽帧用的
+        index_frame = 0  # 记录
+        while 1:
+            ret, frame = cap.read()
+            if not ret:
+                break
+            w, h, _ = frame.shape
+            if w != 1280 and h != 720:
+                frame = cv2.resize(frame, (1280, 720))
+            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.6):
+                continue
+            if not self.change_channel:
+                frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
+            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()
+
+        cap.release()
+        logger.info(f'{video} done')
+
+
+if __name__ == '__main__':
+    VIDEO = 'D:/Project/Hyakkiyakou/OnmyojiAutoScript-hyakkiyakou/temp/sources_video/001-砸百鬼靠技术?在绝对的运气面前,所有技术.mp4'
+    SAVE_PATH = 'D:/Project/Hyakkiyakou/OnmyojiAutoScript-hyakkiyakou/temp/sources_images'
+    t = TransformVideo()
+    t.run(VIDEO, SAVE_PATH)

+ 1 - 1
tasks/KekkaiActivation/assets.py

@@ -88,7 +88,7 @@ class KekkaiActivationAssets:
 	# description 
 	# description 
 	I_CARDS_FISH_6 = RuleImage(roi_front=(193,183,87,91), roi_back=(178,169,110,474), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_6.png")
 	I_CARDS_FISH_6 = RuleImage(roi_front=(193,183,87,91), roi_back=(178,169,110,474), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_6.png")
 	# description 
 	# description 
-	I_CARDS_FISH_5 = RuleImage(roi_front=(192,358,88,21), roi_back=(176,155,105,492), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_5.png")
+	I_CARDS_FISH_5 = RuleImage(roi_front=(192,329,88,90), roi_back=(176,155,116,492), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_5.png")
 	# description 
 	# description 
 	I_CARDS_FISH_4 = RuleImage(roi_front=(192,409,87,21), roi_back=(176,175,118,473), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_4.png")
 	I_CARDS_FISH_4 = RuleImage(roi_front=(192,409,87,21), roi_back=(176,175,118,473), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_4.png")
 	# description 
 	# description