add function to check position and find all matches on screen
This commit is contained in:
+15
-8
@@ -21,7 +21,7 @@ from .command import Command
|
||||
|
||||
class Window:
|
||||
__AUTHOR__ = 'anima'
|
||||
__VERSION__ = '1.0.0'
|
||||
__VERSION__ = '1.1.6'
|
||||
|
||||
key_press_duration = 0.1
|
||||
supported_keys = ['return', 'Up', 'Down', 'Right', 'Left']
|
||||
@@ -95,13 +95,20 @@ class Window:
|
||||
|
||||
img_gray = cv2.cvtColor(command.image, cv2.COLOR_BGR2GRAY)
|
||||
result = cv2.matchTemplate(screen_gray, img_gray, cv2.TM_CCOEFF_NORMED)
|
||||
_, match_value, _, match_pos = cv2.minMaxLoc(result)
|
||||
|
||||
if match_value >= command.threshold and match_value > best_value:
|
||||
logging.debug(f'new best match: {command.name} ({match_value=}%, {match_pos=})')
|
||||
best_match = command
|
||||
best_value = match_value
|
||||
best_pos = match_pos
|
||||
|
||||
locations = numpy.where(result >= command.threshold)
|
||||
matches = list(zip(*locations[::-1])) # [(x1,y1), (x2,y2), ...]
|
||||
|
||||
for match in matches:
|
||||
if command.check_position(match):
|
||||
print('match!')
|
||||
match_value = float(result[match[1], match[0]])
|
||||
if match_value > best_value:
|
||||
best_match = command
|
||||
best_value = match_value
|
||||
best_pos = match
|
||||
logging.debug(f'new best match: {command.name} ({match_value=}%, {match=})')
|
||||
break
|
||||
|
||||
if best_match:
|
||||
return best_match
|
||||
|
||||
Reference in New Issue
Block a user