mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-17 05:52:17 +00:00
refactor: rename image processing methods to use luma instead of binary
This commit is contained in:
@@ -57,12 +57,13 @@ class Button(Resource):
|
|||||||
return load_image(self.file, self.area)
|
return load_image(self.file, self.area)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def image_binary(self):
|
def image_luma(self):
|
||||||
return rgb2gray(self.image)
|
return rgb2luma(self.image)
|
||||||
|
|
||||||
|
|
||||||
def resource_release(self):
|
def resource_release(self):
|
||||||
del_cached_property(self, 'image')
|
del_cached_property(self, 'image')
|
||||||
del_cached_property(self, 'image_binary')
|
del_cached_property(self, 'image_luma')
|
||||||
self.clear_offset()
|
self.clear_offset()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -119,7 +120,7 @@ class Button(Resource):
|
|||||||
|
|
||||||
return sim > similarity
|
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.
|
Detects assets by template matching.
|
||||||
|
|
||||||
@@ -135,8 +136,8 @@ class Button(Resource):
|
|||||||
"""
|
"""
|
||||||
if not direct_match:
|
if not direct_match:
|
||||||
image = crop(image, self.search, copy=False)
|
image = crop(image, self.search, copy=False)
|
||||||
image = rgb2gray(image)
|
image = rgb2luma(image)
|
||||||
res = cv2.matchTemplate(self.image_binary, image, cv2.TM_CCOEFF_NORMED)
|
res = cv2.matchTemplate(self.image_luma, image, cv2.TM_CCOEFF_NORMED)
|
||||||
_, sim, _, point = cv2.minMaxLoc(res)
|
_, sim, _, point = cv2.minMaxLoc(res)
|
||||||
|
|
||||||
self._button_offset = np.array(point) + self.search[:2] - self.area[:2]
|
self._button_offset = np.array(point) + self.search[:2] - self.area[:2]
|
||||||
@@ -254,9 +255,9 @@ class ButtonWrapper(Resource):
|
|||||||
return True
|
return True
|
||||||
return False
|
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:
|
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
|
self._matched_button = assets
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user