Add trust-scored template matching (ambiguity / PSR)#373
Merged
Conversation
match_template returns only the top score and clicks it, but a duplicate toolbar button or a near-identical sibling correlates ~0.95 in two places, so a high score is not an unambiguous match. Add a Lowe-style ratio test for pixel templates: inspect the full correlation surface, compare the global peak to the next-best peak outside an exclusion window, compute PSR, and flag strong-but-ambiguous matches. Reuses a new visual_match._score_map.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 29 |
| Duplication | 4 |
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.



Summary
Adds
match_with_trust/score_peaks— template matching that reports whether a match is trustworthy vs ambiguous, not just above-threshold.match_templatereturns the single best score and clicks it, but a button repeated in a toolbar or a near-identical sibling correlates ~0.95 in two places, so a high score is not an unambiguous match and the matcher can confidently click the wrong one.This adds a Lowe-style ratio test for pixel templates (
feature_matchalready does it for ORB keypoints;match_templatenever did): it inspects the whole correlation surface, compares the global peak to the next-best peak outside an exclusion window, and computes the peak-to-sidelobe ratio (PSR), flagging strong-but-ambiguous matches viais_ambiguous.Reuses a new
visual_match._score_maphelper — the fullmatchTemplatesurface the public matchers discard — so no matching code is duplicated (and it unblocks future score-map features like auto-thresholding and sub-pixel refinement). Injectablehaystack; Qt-free.Layers
utils/match_trust/—TrustedMatch,match_with_trust,score_peaks; plusvisual_match._score_map.je_auto_control+__all__.AC_match_with_trust→{found, match}.ac_match_with_trust(read-only).Tests
test/unit_test/headless/test_match_trust_batch.py— single occurrence is unambiguous (peak_ratio < 0.9), duplicate occurrence is flagged ambiguous (ratio ≥ 0.9, second ≥ 0.9),score_peaksmetric keys,min_scorefilter, PSR present, full wiring + facade exports. 7 passed. ruff / bandit / radon / float-scan / Qt-free all clean.