Add scale_detect: infer display scale / visual DPI from a template#407
Merged
Conversation
A template cropped at 100% scale won't match on a 150%-DPI machine, and match_template returns only the single best match, discarding the per-scale scores. scale_sweep keeps the whole profile (every scale's best match) and detect_scale reports the winning scale as a DPI inference with a confidence margin (how far it beats the runner-up). Reuses visual_match._score_map per scale; cv2/numpy lazily imported.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 25 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
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.



Why
A template cropped at 100% display scale won't match pixel-for-pixel on a machine running at 150% DPI — everything is 1.5x bigger.
visual_match.match_templatecan sweep scales, but it returns only the single best match's location and throws the per-scale scores away.scale_detectkeeps the whole profile:scale_sweep— the per-scale score profile (every scale's best match)detect_scale— the winning scale as a DPI inference (scale_percent) with a confidencemargin(how far it beats the runner-up)So an automation can infer the effective UI scale / DPI and how confident that inference is — the per-scale scores
match_templatediscards.Design
visual_match._score_map(the fullmatchTemplatesurface, oriented higher = better) for each scale; source is any ndarray / path / PIL image, or the live screen.scalesdefaults to the common Windows values(1.0, 1.25, 1.5, 1.75, 2.0). Scales at which the template exceeds the haystack are skipped;detect_scalereturnsNonewhen none fit. cv2/numpy lazily imported.__all__→AC_detect_scale/AC_scale_sweep→ read-onlyac_*MCP tools → Script Builder (Image). Qt-free verified.Tests
test/unit_test/headless/test_scale_detect_batch.py(cv2 viaimportorskip) — embeds a template resized by a known factor into a canvas and assertsdetect_scalerecovers that scale (1.5x→150%, 1.0x→100%, 2.0x via the executor path), the full sweep profile + keys, the margin confidence, and the too-bigNone/[]cases. Usespytest.approx(no float==). 15 passed with theimage_qualitysibling.