refactor: rename image processing methods to use luma instead of binary

This commit is contained in:
2026-07-06 22:40:30 +08:00
parent f30deb0614
commit e15eb7a9a5
+9 -8
View File
@@ -57,12 +57,13 @@ class Button(Resource):
return load_image(self.file, self.area)
@cached_property
def image_binary(self):
return rgb2gray(self.image)
def image_luma(self):
return rgb2luma(self.image)
def resource_release(self):
del_cached_property(self, 'image')
del_cached_property(self, 'image_binary')
del_cached_property(self, 'image_luma')
self.clear_offset()
def __str__(self):
@@ -119,7 +120,7 @@ class Button(Resource):
return sim > similarity
def match_template_binary(self, image, similarity=0.85, direct_match=False) -> bool:
def match_template_luma(self, image, similarity=0.85, direct_match=False) -> bool:
"""
Detects assets by template matching.
@@ -135,8 +136,8 @@ class Button(Resource):
"""
if not direct_match:
image = crop(image, self.search, copy=False)
image = rgb2gray(image)
res = cv2.matchTemplate(self.image_binary, image, cv2.TM_CCOEFF_NORMED)
image = rgb2luma(image)
res = cv2.matchTemplate(self.image_luma, image, cv2.TM_CCOEFF_NORMED)
_, sim, _, point = cv2.minMaxLoc(res)
self._button_offset = np.array(point) + self.search[:2] - self.area[:2]
@@ -254,9 +255,9 @@ class ButtonWrapper(Resource):
return True
return False
def match_template_binary(self, image, similarity=0.85, direct_match=False) -> bool:
def match_template_luma(self, image, similarity=0.85, direct_match=False) -> bool:
for assets in self.buttons:
if assets.match_template_binary(image, similarity=similarity, direct_match=direct_match):
if assets.match_template_luma(image, similarity=similarity, direct_match=direct_match):
self._matched_button = assets
return True
return False