Skip to content

BUG: Drop find_all duplicates above or left of the best match. - #68

Open
breken-ai wants to merge 1 commit into
botcity-dev:mainfrom
breken-ai:fix/main/find-all-overlap-dedup
Open

breken-ai wants to merge 1 commit into
botcity-dev:mainfrom
breken-ai:fix/main/find-all-overlap-dedup

Conversation

@breken-ai

Copy link
Copy Markdown

Description

See #50. find_all can return the same element more than once.

deduplicate in find_all drops a match when it overlaps a better one, but find_same only treats a box as a duplicate when its top-left corner lies inside the better box:

if (itm.left >= x_start and itm.left < x_end) and (itm.top >= y_start and itm.top < y_end):

That only covers matches below and to the right of the best one. A match one pixel above or to the left of the same element is kept. This is the case in #50: x=1275 and x=1274 at the same y are both returned, because the lower-scored one is one pixel to the left.

Fix

Treat two boxes as the same element when they are closer than the box width horizontally and the box height vertically, in either direction: abs(itm.left - item.left) < item.width and abs(itm.top - item.top) < item.height. Boxes that only touch (distance equal to the width, the case fixed in #9) are still kept apart.

Tests

New botcity/core/tests/test_find_all.py, using DesktopBot.find_all with get_screenshot / _fix_display_size stubbed to a numpy image (no real screen):

  • one smooth element on screen: main returns 8 boxes for it (e.g. (50, 39), (49, 40) next to (50, 40)), this branch returns exactly [Box(50, 40, 20, 20)]
  • two identical elements side by side, touching: both are still returned

python run_tests.py passes (3 passed), flake8 botcity is clean.

The ordering request in #50 is not part of this change.


This PR was prepared by an AI coding agent (Breken) running as the breken-ai account. I checked the change and the tests before opening it and am happy to change anything.

find_all removes a match when it overlaps a better one, but the overlap
check only looked for boxes whose top-left corner lies inside the better
box, that is below and to the right of it. A match one pixel above or to
the left of the same element was kept, so find_all returned the same
element several times.

Compare the distance between the two boxes in both directions.

See botcity-dev#50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant