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

fix(Component): Expand the range of image matching #1029

ryland 1 год назад
Родитель
Сommit
a0b7aa961a

+ 2 - 2
dev_tools/assets_test.py

@@ -34,10 +34,10 @@ def detect_ocr(file: str, target: RuleOcr):
 
 
 
 
 # 图片文件路径 可以是相对路径
 # 图片文件路径 可以是相对路径
-IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\465610922-c9f6f975-0159-4e24-a569-88aa3e862d70.png"
+IMAGE_FILE = r"C:\Users\Ryland\Desktop\wechat_2025-09-11_130558_801.png"
 if __name__ == '__main__':
 if __name__ == '__main__':
     from tasks.Exploration.script_task import ScriptTask
     from tasks.Exploration.script_task import ScriptTask
-    targe = ScriptTask.I_CLOUD
+    targe = ScriptTask.I_ADD_2
     print(detect_image(IMAGE_FILE, targe))
     print(detect_image(IMAGE_FILE, targe))
 
 
     # ocr demo
     # ocr demo

+ 5 - 1
module/atom/image.py

@@ -11,7 +11,9 @@ from module.base.decorator import cached_property
 from module.logger import logger
 from module.logger import logger
 from module.base.utils import is_approx_rectangle
 from module.base.utils import is_approx_rectangle
 
 
+
 class RuleImage:
 class RuleImage:
+    debug_mode: bool = False
 
 
     def __init__(self, roi_front: tuple, roi_back: tuple, method: str, threshold: float, file: str) -> None:
     def __init__(self, roi_front: tuple, roi_back: tuple, method: str, threshold: float, file: str) -> None:
         """
         """
@@ -156,7 +158,8 @@ class RuleImage:
 
 
         res = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
         res = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
         min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)  # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标
         min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)  # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标
-        # logger.attr(self.name, max_val)
+        if self.debug_mode:
+            logger.attr(self.name, f'matching score {max_val:.5f}')
 
 
         if max_val > threshold:
         if max_val > threshold:
             self.roi_front[0] = max_loc[0] + self.roi_back[0]
             self.roi_front[0] = max_loc[0] + self.roi_back[0]
@@ -218,6 +221,7 @@ class RuleImage:
         return int(x + w//2), int(y + h//2)
         return int(x + w//2), int(y + h//2)
 
 
     def test_match(self, image: np.array):
     def test_match(self, image: np.array):
+        self.debug_mode = True
         if self.is_template_match:
         if self.is_template_match:
             return self.match(image)
             return self.match(image)
         if self.is_sift_flann:
         if self.is_sift_flann:

+ 2 - 2
tasks/Component/GeneralInvite/assets.py

@@ -12,9 +12,9 @@ class GeneralInviteAssets:
 
 
 	# Image Rule Assets
 	# Image Rule Assets
 	# 中间的邀请图片 
 	# 中间的邀请图片 
-	I_ADD_1 = RuleImage(roi_front=(592,288,114,51), roi_back=(592,288,114,51), threshold=0.9, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_add_1.png")
+	I_ADD_1 = RuleImage(roi_front=(596,241,114,51), roi_back=(569,196,186,161), threshold=0.9, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_add_1.png")
 	# 最右边的邀请 
 	# 最右边的邀请 
-	I_ADD_2 = RuleImage(roi_front=(1039,205,100,100), roi_back=(1039,205,100,100), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_add_2.png")
+	I_ADD_2 = RuleImage(roi_front=(1013,249,100,100), roi_back=(970,151,193,220), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_add_2.png")
 	# description 
 	# description 
 	I_FIRE_FAIL = RuleImage(roi_front=(1177,604,81,74), roi_back=(1177,604,81,74), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_fire_fail.png")
 	I_FIRE_FAIL = RuleImage(roi_front=(1177,604,81,74), roi_back=(1177,604,81,74), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_fire_fail.png")
 	# description 
 	# description 

+ 4 - 4
tasks/Component/GeneralInvite/gi/image.json

@@ -2,8 +2,8 @@
   {
   {
     "itemName": "add_1",
     "itemName": "add_1",
     "imageName": "gi_add_1.png",
     "imageName": "gi_add_1.png",
-    "roiFront": "592,288,114,51",
-    "roiBack": "592,288,114,51",
+    "roiFront": "596,241,114,51",
+    "roiBack": "569,196,186,161",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.9,
     "threshold": 0.9,
     "description": "中间的邀请图片"
     "description": "中间的邀请图片"
@@ -11,8 +11,8 @@
   {
   {
     "itemName": "add_2",
     "itemName": "add_2",
     "imageName": "gi_add_2.png",
     "imageName": "gi_add_2.png",
-    "roiFront": "1039,205,100,100",
-    "roiBack": "1039,205,100,100",
+    "roiFront": "1013,249,100,100",
+    "roiBack": "970,151,193,220",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "最右边的邀请"
     "description": "最右边的邀请"