huangrunheng 2 лет назад
Родитель
Сommit
ae65a976d7
3 измененных файлов с 58 добавлено и 3 удалено
  1. 1 1
      .gitignore
  2. 3 2
      tasks/Hyakkiyakou/prepare/get_images.py
  3. 54 0
      tasks/Hyakkiyakou/script_task.py

+ 1 - 1
.gitignore

@@ -33,7 +33,7 @@ module/config/argument/setting.json
 !dev_tools/Spyxx/spyxx_amd64.exe
 !dev_tools/ViewWizard2/ViewWizard2.exe
 !dev_tools/ViewWizard3/ViewWizard.exe
-
+hya
 
 
 

+ 3 - 2
tasks/Hyakkiyakou/prepare/get_images.py

@@ -25,7 +25,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
     def run(self):
         self.ui_get_current_page()
         self.ui_goto(page_hyakkiyakou)
-        for i in range(40):
+        for i in range(1):
             self.save_one()
 
     def save_one(self):
@@ -49,7 +49,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
                 self.click(click_button, interval=1)
         self.device.stuck_record_add('BATTLE_STATUS_S')
         # 保存图片
-        save_img_timer = Timer(0.2)
+        save_img_timer = Timer(0.35)
         save_img_timer.start()
         while 1:
             self.screenshot()
@@ -75,6 +75,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
         time_now2 = time_now1 + 1
         cv2.imwrite(str(self.save_folder / f'{time_now1}.png'), img1)
         cv2.imwrite(str(self.save_folder / f'{time_now2}.png'), img2)
+        cv2.imwrite(str(self.save_folder / f'all{time_now1}.png'), image)
 
 
 if __name__ == '__main__':

+ 54 - 0
tasks/Hyakkiyakou/script_task.py

@@ -0,0 +1,54 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import cv2
+import numpy as np
+
+from datetime import datetime
+from numpy import uint8, fromfile
+# Use cmd to install: ./toolkit/python.exe -m pip install -i https://pypi.org/simple/ oashya --trusted-host pypi.org
+from oashya.tracker import Tracker
+
+
+def plot_save(image, boxes):
+    color_palette = np.random.uniform(0, 255, size=(226, 3))
+    for box in boxes:
+        _cls = box[0]
+        _scores = box[1]
+        _x, _y, _w, _h = box[2]
+        x1 = int(_x - _w / 2)
+        y1 = int(_y - _h / 2)
+        x2 = int(_x + _w / 2)
+        y2 = int(_y + _h / 2)
+        cv2.rectangle(image, (x1, y1), (x2, y2), color_palette[_cls], 2)
+        #
+        cv2.putText(image, f'{_cls} {_scores:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color_palette[_cls],
+                    2)
+    save_file = './tasks/Hyakkiyakou/temp/image.png'
+    cv2.imwrite(save_file, image)
+
+def test_():
+    args = {
+        'dual_detect': True,
+        'conf_threshold': 0.5,
+        'iou_threshold': 0.6,
+        'precision': 'int8',
+    }
+    tracker = Tracker(args=args)
+    # --------------------------------
+    file_img = './tasks/Hyakkiyakou/temp/20240526T103931/all1716691228563.png'
+    img = cv2.imdecode(fromfile(str(file_img), dtype=uint8), -1)
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    resutl = tracker.detect(img)
+    start_time = datetime.now()
+    resutl = tracker.detect(img)
+    end_time = datetime.now()
+    print(f'Cost time: {(end_time - start_time).total_seconds() * 1000} ms')
+    for one in resutl:
+        print(one)
+    plot_save(img, resutl)
+
+
+
+if __name__ == '__main__':
+    test_()