Skip to content

Add trust-scored template matching (ambiguity / PSR)#373

Merged
JE-Chen merged 1 commit into
devfrom
feat/match-trust-batch
Jun 23, 2026
Merged

Add trust-scored template matching (ambiguity / PSR)#373
JE-Chen merged 1 commit into
devfrom
feat/match-trust-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds match_with_trust / score_peaks — template matching that reports whether a match is trustworthy vs ambiguous, not just above-threshold. match_template returns 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_match already does it for ORB keypoints; match_template never 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 via is_ambiguous.

Reuses a new visual_match._score_map helper — the full matchTemplate surface the public matchers discard — so no matching code is duplicated (and it unblocks future score-map features like auto-thresholding and sub-pixel refinement). Injectable haystack; Qt-free.

Layers

  • Core: utils/match_trust/TrustedMatch, match_with_trust, score_peaks; plus visual_match._score_map.
  • Facade: re-exported from je_auto_control + __all__.
  • Executor: AC_match_with_trust{found, match}.
  • MCP: ac_match_with_trust (read-only).
  • Script Builder: Match Template (trust-scored) under Image.
  • Docs: v161 EN + Zh + toctree. Changelog: root EN + zh-TW + zh-CN.

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_peaks metric keys, min_score filter, PSR present, full wiring + facade exports. 7 passed. ruff / bandit / radon / float-scan / Qt-free all clean.

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.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 29 complexity · 4 duplication

Metric Results
Complexity 29
Duplication 4

View in Codacy

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.

@JE-Chen JE-Chen merged commit 57d3087 into dev Jun 23, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/match-trust-batch branch June 23, 2026 18:44
@sonarqubecloud

Copy link
Copy Markdown

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