From d27676cfe6fd54df4668f714d0774655e2eb0bc5 Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Fri, 24 Apr 2026 01:57:20 +0200 Subject: [PATCH] fix: cap adattivo al 50% varianti + form e finestra risultati ridimensionabili MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - max_vars_full = max(max_matches*8, n_variants // 2): protegge perf con molte scale mantenendo metà delle varianti al full-res (vs intero senza cap che dava 22s su 864 varianti, vs 80s screenshot utente) - Dialog tkinter: resizable, minsize 360x420, Entry col peso 2 espandibile - Finestra risultati cv2: WINDOW_NORMAL con resizeWindow iniziale 1600x900 Co-Authored-By: Claude Opus 4.7 (1M context) --- pm2d/gui.py | 15 +++++++++++++-- pm2d/line_matcher.py | 7 +++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pm2d/gui.py b/pm2d/gui.py index 78cfd6c..418b53d 100644 --- a/pm2d/gui.py +++ b/pm2d/gui.py @@ -55,21 +55,29 @@ def edit_params(defaults: dict, template_bgr: np.ndarray | None = None) -> dict """ root = tk.Tk() root.title("Parametri Pattern Matching 2D") + root.resizable(True, True) + root.minsize(360, 420) try: root.attributes("-topmost", True) except Exception: pass + # Grid root: fa espandere la cella (0, 0) + root.columnconfigure(0, weight=1) + root.rowconfigure(0, weight=1) + result: dict = {} entries: dict[str, tk.Entry] = {} frame = ttk.Frame(root, padding=12) frame.grid(row=0, column=0, sticky="nsew") + frame.columnconfigure(0, weight=1) + frame.columnconfigure(1, weight=2) for i, (key, label, _typ) in enumerate(PARAM_SCHEMA): ttk.Label(frame, text=label).grid(row=i, column=0, sticky="w", padx=4, pady=3) - e = ttk.Entry(frame, width=14) + e = ttk.Entry(frame) e.insert(0, str(defaults.get(key, ""))) - e.grid(row=i, column=1, padx=4, pady=3) + e.grid(row=i, column=1, padx=4, pady=3, sticky="ew") entries[key] = e hint_var = tk.StringVar(value="") @@ -392,6 +400,9 @@ def show_results( else: composed = annotated disp = _fit_for_display(composed, max_side=1600) + cv2.namedWindow(WINDOW_RESULT, cv2.WINDOW_NORMAL) + cv2.resizeWindow(WINDOW_RESULT, min(disp.shape[1], 1600), + min(disp.shape[0], 900)) cv2.imshow(WINDOW_RESULT, disp) print("\n[r] parametri [o] nuovo ROI [m] nuovo modello [s] nuova scena [q/Esc] chiudi") action = "quit" diff --git a/pm2d/line_matcher.py b/pm2d/line_matcher.py index 4a4f83d..623fed5 100644 --- a/pm2d/line_matcher.py +++ b/pm2d/line_matcher.py @@ -542,9 +542,12 @@ class LineShapeMatcher: if not kept_variants: return [] - # Cap: tutte le varianti che superano top_thresh passano al full-res. - # Ordinamento per score decrescente (early matches hanno priorità). + # Cap adattivo: ordina per score top-level e mantieni le più promettenti. + # Min: max_matches*8 (margine per NMS cross-variant) + # Max: 50% delle varianti totali (protegge performance con molte scale) kept_variants.sort(key=lambda t: -t[1]) + max_vars_full = max(max_matches * 8, len(self.variants) // 2) + kept_variants = kept_variants[:max_vars_full] # Full-res (parallelizzato per variante) resp0 = self._response_map(gray0)