From 934b5648a29811e3ab029cd0740698e90024fc55 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Mon, 16 Mar 2026 13:56:12 +0100 Subject: [PATCH] debug: add detailed skip-reason logging to graphic detection Co-Authored-By: Claude Opus 4.6 --- klausur-service/backend/cv_graphic_detect.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/klausur-service/backend/cv_graphic_detect.py b/klausur-service/backend/cv_graphic_detect.py index 06da34f..7f01e46 100644 --- a/klausur-service/backend/cv_graphic_detect.py +++ b/klausur-service/backend/cv_graphic_detect.py @@ -264,19 +264,28 @@ def detect_graphic_elements( # --- 5. Analyse and classify --- candidates: List[GraphicElement] = [] + skip_reasons: Dict[str, int] = {} for cnt in contours: area = cv2.contourArea(cnt) if area < min_area or area > max_area: + bx, by, bw, bh = cv2.boundingRect(cnt) + reason = f"area={int(area)}<{min_area}" if area < min_area else f"area={int(area)}>{max_area}" + logger.debug("GraphicDetect SKIP: %s at (%d,%d) %dx%d", reason, bx, by, bw, bh) + skip_reasons[f"area_filter"] = skip_reasons.get("area_filter", 0) + 1 continue bx, by, bw, bh = cv2.boundingRect(cnt) if bw < 8 or bh < 8: + skip_reasons["too_small_dim"] = skip_reasons.get("too_small_dim", 0) + 1 continue # Skip elements that overlap significantly with the exclusion zone roi_excl = exclusion[by:by + bh, bx:bx + bw] excl_ratio = np.sum(roi_excl > 0) / (bw * bh) if bw * bh > 0 else 0 if excl_ratio > 0.4: + logger.debug("GraphicDetect SKIP excl_ratio=%.2f at (%d,%d) %dx%d area=%d", + excl_ratio, bx, by, bw, bh, int(area)) + skip_reasons["excl_overlap"] = skip_reasons.get("excl_overlap", 0) + 1 continue # Classify shape @@ -284,6 +293,9 @@ def detect_graphic_elements( # Skip noise (too small or text-like) if shape == "noise": + logger.debug("GraphicDetect SKIP noise at (%d,%d) %dx%d area=%d", + bx, by, bw, bh, int(area)) + skip_reasons["noise"] = skip_reasons.get("noise", 0) + 1 continue # Determine dominant color @@ -304,6 +316,10 @@ def detect_graphic_elements( contour=cnt, )) + if skip_reasons: + logger.info("GraphicDetect: skipped contours: %s", + ", ".join(f"{k}={v}" for k, v in sorted(skip_reasons.items()))) + # Sort by area descending, limit count candidates.sort(key=lambda g: g.area, reverse=True) result = candidates[:max_elements]