Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
See #50.
find_allcan return the same element more than once.deduplicateinfind_alldrops a match when it overlaps a better one, butfind_sameonly treats a box as a duplicate when its top-left corner lies inside the better box: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=1275andx=1274at the sameyare 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, usingDesktopBot.find_allwithget_screenshot/_fix_display_sizestubbed to a numpy image (no real screen):mainreturns 8 boxes for it (e.g.(50, 39),(49, 40)next to(50, 40)), this branch returns exactly[Box(50, 40, 20, 20)]python run_tests.pypasses (3 passed),flake8 botcityis 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-aiaccount. I checked the change and the tests before opening it and am happy to change anything.