Skip to content

Commit

Permalink
fix: infinite loop when template has multiple match
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Jun 20, 2021
1 parent 2216dcc commit 71e9e06
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion auto_derby/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def match_image_until_disappear(
for i in sort(template.match(template.screenshot(max_age=0), *tmpl)):
count += 1
yield i
break # actions will make screenshot outdate
if count == 0:
break

Expand Down
6 changes: 3 additions & 3 deletions auto_derby/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ def _match_one(
mask = cv_pos[0 : res.shape[0], 0 : res.shape[1]]
_, max_val, _, max_loc = cv2.minMaxLoc(res, mask=mask)
x, y = max_loc
x, y = reverse_rp.vector2((x, y), TARGET_WIDTH)
if max_val < tmpl.threshold or not tmpl.match(img, (x, y)):
client_pos = reverse_rp.vector2((x, y), TARGET_WIDTH)
if max_val < tmpl.threshold or not tmpl.match(img, client_pos):
LOGGER.debug(
"not match: tmpl=%s, pos=%s, similarity=%.3f", tmpl, max_loc, max_val
)
break
LOGGER.info("match: tmpl=%s, pos=%s, similarity=%.2f", tmpl, max_loc, max_val)
yield (tmpl, (x, y))
yield (tmpl, client_pos)

# mark position unavailable to avoid overlap
cv_pos[max(0, y - tmpl_h) : y + tmpl_h, max(0, x - tmpl_w) : x + tmpl_w] = 0
Expand Down

0 comments on commit 71e9e06

Please sign in to comment.