|
| 1 | +Pre-Match Settle Gating + Match Persistence |
| 2 | +=========================================== |
| 3 | + |
| 4 | +Matching mid-animation is a top flakiness source: the spinner is still spinning, a transition |
| 5 | +is half-done, and the matcher fires on a transient. ``smart_waits.wait_until_screen_stable`` |
| 6 | +gates a *live polling loop* and returns a boolean — it cannot score stability on an *injectable* |
| 7 | +sequence of frames, nor tell you whether a *match* held steady across them. ``match_stability`` |
| 8 | +adds both, on injected frames so it is unit-testable: ``region_stability`` scores how settled a |
| 9 | +frame sequence is (consecutive-frame SSIM), and ``match_persistence`` checks that a template's |
| 10 | +hit holds at the same place across the frames (low jitter), not just in one lucky frame. |
| 11 | + |
| 12 | +It reuses ``ssim.ssim_compare``, ``visual_match.match_template`` and |
| 13 | +``grounding_consensus.consensus_point`` — no new matching code. The frames are injectable |
| 14 | +(ndarray / path / PIL). Imports no ``PySide6``. |
| 15 | + |
| 16 | +Headless API |
| 17 | +------------ |
| 18 | + |
| 19 | +.. code-block:: python |
| 20 | +
|
| 21 | + from je_auto_control import region_stability, match_persistence |
| 22 | +
|
| 23 | + frames = [grab(), grab(), grab()] # a few snapshots of the same region |
| 24 | + if region_stability(frames, settle_threshold=0.99)["stable"]: |
| 25 | + do_the_match() |
| 26 | +
|
| 27 | + result = match_persistence("button.png", frames, min_score=0.8, agree_px=8) |
| 28 | + if result["persisted"]: |
| 29 | + print("steady hit, jitter", result["jitter"]) |
| 30 | +
|
| 31 | +``region_stability`` returns ``{stable, mean_ssim, min_ssim}`` — ``stable`` when the lowest |
| 32 | +consecutive-frame SSIM clears ``settle_threshold``. ``match_persistence`` returns |
| 33 | +``{persisted, n_hits, jitter}`` — ``persisted`` when the template is found in *every* frame and |
| 34 | +the hit centres agree within ``agree_px`` (``jitter`` is their spread; 0 = rock steady). |
| 35 | + |
| 36 | +Executor commands |
| 37 | +----------------- |
| 38 | + |
| 39 | +``AC_region_stability`` (``frames`` / ``settle_threshold`` → ``{stable, mean_ssim, min_ssim}``) |
| 40 | +and ``AC_match_persistence`` (``template`` / ``frames`` / ``min_score`` / ``agree_px`` → |
| 41 | +``{persisted, n_hits, jitter}``). They are exposed as the MCP tools ``ac_region_stability`` / |
| 42 | +``ac_match_persistence`` (read-only) and as the Script Builder commands **Region Stability |
| 43 | +(frames)** / **Match Persistence (frames)** under **Image**. |
0 commit comments