Răsfoiți Sursa

fix(GeneralInvite): Match selected friend tabs by template color #40

(cherry picked from commit 4b1a06d1085d1f07b9a3d46187ac801d6df6ecb6)
blylana 15 ore în urmă
părinte
comite
88be4ad87e
2 a modificat fișierele cu 10 adăugiri și 6 ștergeri
  1. 7 2
      module/atom/image.py
  2. 3 4
      tasks/Component/GeneralInvite/general_invite.py

+ 7 - 2
module/atom/image.py

@@ -544,6 +544,10 @@ class RuleImage(RuleImageMallResourceMixin):
             cv2.destroyAllWindows()
         return result
 
+    @cached_property
+    def mean_color(self) -> tuple:
+        return tuple(cv2.mean(self.image)[:3])
+
     def match_mean_color(self, image, color: tuple, bias=10) -> bool:
         """
 
@@ -552,10 +556,11 @@ class RuleImage(RuleImageMallResourceMixin):
         :param bias:
         :return:
         """
-        image = self.corp(image)
+        image = self.corp(image, self.roi_front)
         average_color = cv2.mean(image)
+        self.debug_mode = True
         if self.debug_mode:
-            logger.info(f'{self.name} average_color: {average_color}')
+            logger.info(f'{self.name} average_color: {average_color}, template: {color}, bias: {bias}')
         for i in range(3):
             if abs(average_color[i] - color[i]) > bias:
                 return False

+ 3 - 4
tasks/Component/GeneralInvite/general_invite.py

@@ -392,7 +392,7 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
             recent_index = friend_class.index('最近')
             while recent_index == 1:
                 self.screenshot()
-                if self.appear(self.I_FLAG_2_ON):
+                if self.I_FLAG_2_ON.match_mean_color(self.device.image, self.I_FLAG_2_ON.mean_color, 10):
                     break
                 if self.appear_then_click(self.I_FLAG_2_OFF, interval=1):
                     continue
@@ -415,16 +415,15 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
             if is_select:
                 continue
             # 首先切换到不同的好友列表
-            INVITE_FLAG_ON = (227, 193, 153)
             while index == 0:
                 self.screenshot()
-                if self.I_FLAG_1_ON.match_mean_color(self.device.image, INVITE_FLAG_ON, 10):
+                if self.I_FLAG_1_ON.match_mean_color(self.device.image, self.I_FLAG_1_ON.mean_color, 10):
                     break
                 if self.click(self.I_FLAG_1_OFF, interval=1):
                     continue
             while index == 1:
                 self.screenshot()
-                if self.appear(self.I_FLAG_2_ON):
+                if self.I_FLAG_2_ON.match_mean_color(self.device.image, self.I_FLAG_2_ON.mean_color, 10):
                     break
                 if self.appear_then_click(self.I_FLAG_2_OFF, interval=1):
                     continue