debug: add detailed skip-reason logging to graphic detection
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 30s
CI / test-python-klausur (push) Has been cancelled
CI / test-python-agent-core (push) Has been cancelled
CI / test-nodejs-website (push) Has been cancelled
CI / test-go-edu-search (push) Has been cancelled
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 30s
CI / test-python-klausur (push) Has been cancelled
CI / test-python-agent-core (push) Has been cancelled
CI / test-nodejs-website (push) Has been cancelled
CI / test-go-edu-search (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user