From 90ee8ca8f46fc3dc91536d430dfc827151702292 Mon Sep 17 00:00:00 2001 From: Dom Date: Sat, 4 Apr 2026 23:23:21 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20template=20matching=20sur=20fen=C3=AAtre?= =?UTF-8?q?=20active=20+=20seuil=200.90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Template matching des icônes limité à la fenêtre active (window.png) pour éviter les faux positifs sur le full screen. Seuil relevé de 0.70 à 0.90. Coordonnées fenêtre converties en coordonnées écran. Co-Authored-By: Claude Opus 4.6 (1M context) --- agent_v0/server_v1/api_stream.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/agent_v0/server_v1/api_stream.py b/agent_v0/server_v1/api_stream.py index 8c2069d55..c767ff063 100644 --- a/agent_v0/server_v1/api_stream.py +++ b/agent_v0/server_v1/api_stream.py @@ -5200,14 +5200,31 @@ def _resolve_target_sync( return grounding_result if not by_text_strict or by_text_source != "ocr": + # Template matching sur la fenêtre active si disponible (évite les faux positifs) + window_capture = target_spec.get("window_capture", {}) + window_rect = window_capture.get("rect") + from pathlib import Path as _Path + _full = _Path(screenshot_path) + _win = _full.parent / _full.name.replace("_full.png", "_window.png") + tm_path = str(_win) if _win.is_file() and window_rect else screenshot_path + tm_screen_w = (window_rect[2] - window_rect[0]) if window_rect and _win.is_file() else screen_width + tm_screen_h = (window_rect[3] - window_rect[1]) if window_rect and _win.is_file() else screen_height + result = _resolve_by_template_matching( - screenshot_path=screenshot_path, + screenshot_path=tm_path, anchor_image_b64=anchor_image_b64, - screen_width=screen_width, - screen_height=screen_height, - confidence_threshold=0.70, + screen_width=tm_screen_w, + screen_height=tm_screen_h, + confidence_threshold=0.90, ) - if result and result.get("score", 0) >= 0.70: + if result and result.get("score", 0) >= 0.90: + x_tm, y_tm = result["x_pct"], result["y_pct"] + # Convertir coordonnées fenêtre → écran si nécessaire + if window_rect and _win.is_file(): + abs_x = window_rect[0] + x_tm * tm_screen_w + abs_y = window_rect[1] + y_tm * tm_screen_h + result["x_pct"] = round(abs_x / screen_width, 6) + result["y_pct"] = round(abs_y / screen_height, 6) logger.info( "Strict resolve TEMPLATE : icon match (score=%.3f)", result.get("score", 0),