Răsfoiți Sursa

!2 add cv find

pcacc 4 luni în urmă
părinte
comite
b1a1a1652b
2 a modificat fișierele cu 42 adăugiri și 6 ștergeri
  1. 2 2
      dongri_task.py
  2. 40 4
      scriptBase/imgFind.py

+ 2 - 2
dongri_task.py

@@ -1173,7 +1173,7 @@ if __name__ == '__main__':
     #task_fightMonster(False, False,False).run()
     #task_checkHelp().run()
     #task_checkStoreRoom().run()
-    task_activity_lianmeng().run()
+    #task_activity_lianmeng().run()
     #task_fight_yongbing(True).run()
     #task_collect([4,3,2,1]).run()
     #task_train("upgrade").run()
@@ -1185,5 +1185,5 @@ if __name__ == '__main__':
     #task_collect(3).run()
     #task_collect(4).run()
     #task_returnAllLine().run()
-    #task_paticipateInTeam().run()
+    task_paticipateInTeam().run()
     #task_fight_jina(True).run()

+ 40 - 4
scriptBase/imgFind.py

@@ -133,7 +133,7 @@ class pcacc_img:
     def find_all_img(image_path):
 
         # 设置查找的置信度(confidence)阈值,范围从0到1,默认为0.999
-        confidence_threshold = 0.85
+        confidence_threshold = 0.95
 
         # 查找模糊图片在屏幕上的位置
         positions = pyautogui.locateAllOnScreen(image_path, confidence=confidence_threshold)
@@ -142,6 +142,43 @@ class pcacc_img:
             return False, []
 
         return True, positions
+    
+    @staticmethod
+    def find_img_cv(image_path, region=None):
+        # 读取模板和屏幕截图
+        confidence_threshold = 0.95
+
+        template = cv2.imread(image_path, cv2.IMREAD_COLOR)
+        screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=region)), cv2.COLOR_RGB2BGR)
+        
+        # 模板匹配
+        result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED)
+        _, max_val, _, max_loc = cv2.minMaxLoc(result)
+        
+        if max_val > confidence_threshold:  # 置信度阈值
+            left, top = max_loc  # 左上角坐标
+            width, height = template.shape[1], template.shape[0]  # 模板宽高
+
+            #mid
+            mid_left = int(left + width / 4)
+            mid_right = int(left + width / 4 * 3)
+            mid_top = int(top + height / 4)
+            mid_bottom = int(top + height / 4 * 3)
+
+            #want_position
+            want_x = random.randint(mid_left, mid_right)
+            want_y = random.randint(mid_top, mid_bottom)
+
+            #dst_position
+            dst_x = random.randint(int(want_x - width / 3), int(want_x + width / 3))
+            dst_y = random.randint(int(want_y - height / 3), int(want_y + height / 3))
+            
+
+            print(f"{image_path}:({dst_x}, {dst_y})")
+            return True, (dst_x, dst_y)
+        else:
+            print(f"{image_path} cv图片未找到")
+            return False, (-1, -1)
 
     @staticmethod
     def find_img(image_path):
@@ -154,7 +191,6 @@ class pcacc_img:
 
         if position is not None:
             # 图片找到了,获取图片的中心点坐标
-
             #mid
             mid_left = int(position.left + position.width / 4)
             mid_right = int(position.left + position.width / 4 * 3)
@@ -179,7 +215,7 @@ class pcacc_img:
     @staticmethod
     def find_imgArr(imgArr):
         for cur_img in imgArr:
-            ret, pos = pcacc_img.find_img(cur_img)
+            ret, pos = pcacc_img.find_img_cv(cur_img)
             if ret:
                 return ret, pos
         return False, None
@@ -187,7 +223,7 @@ class pcacc_img:
     @staticmethod
     def find_imgs(images):
         if isinstance(images, str):
-            return pcacc_img.find_img(images)
+            return pcacc_img.find_img_cv(images)
         elif isinstance(images, (list, tuple)):
             return pcacc_img.find_imgArr(images)
         else: