Add auto-thresholded template matching (Otsu on score map)#376
Merged
Conversation
Every match_template_all call forces a hand-tuned min_score: too low floods NMS, too high drops re-themed targets, and the right value differs per asset. Run Otsu on the correlation score histogram to find the valley between background correlation and real matches, returning that cut-off plus a separability score so a unimodal (no-match) surface is flagged. match_auto returns one peak per above-threshold region via connected_boxes.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 28 |
| Duplication | 1 |
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.
ccoeff_normed scores span [-1, 1], so the Otsu cut-off can legitimately be negative on some OpenCV builds (match_auto clamps it with floor anyway). Assert the threshold is below a perfect match and use a relative separability check (bimodal > flat) instead of absolute bounds.
|
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.



摘要
新增
match_auto/auto_threshold— 從相關性分數圖自動推導比對門檻,免除手調min_score。每次match_template_all都迫使呼叫者猜min_score(太低淹沒 NMS、太高漏掉縮放/換膚目標,且因素材與畫面而異)。本功能對相關性分數直方圖套用 Otsu(而非像素強度,後者是
preprocess.binarize的做法),找出「背景相關」與「真正匹配」之間的谷,並回傳該門檻加上 separability 分離度,讓呼叫端在直方圖為單峰(無明確匹配)時知道不可信任該門檻。match_auto透過connected_boxes對每個過門檻連通區只回傳單一峰,避免原始像素掃描 + NMS 在寬相關峰上留下的重複命中,並以floor夾住門檻。重用新增的
visual_match._score_map(公開比對器丟棄的完整 matchTemplate 曲面);haystack可注入;Qt-free。五層
utils/match_autothresh/—auto_threshold、match_auto。je_auto_control匯出 +__all__。AC_match_auto({count, matches})/AC_auto_threshold({found, info})。ac_match_auto/ac_auto_threshold(read-only)。測試
test/unit_test/headless/test_match_autothresh_batch.py— auto_threshold 指標、雙峰可分離度 > 0.3、match_auto 找到兩個目標、blank 用 floor 擋住雜訊、blank separability < 0.3、wiring + facade。6 passed。ruff / bandit / radon / float-scan / Qt-free 全乾淨。