Skip to content

Add image_quality: sharpness/contrast/brightness gate before OCR#406

Merged
JE-Chen merged 1 commit into
devfrom
feat/image-quality-batch
Jun 24, 2026
Merged

Add image_quality: sharpness/contrast/brightness gate before OCR#406
JE-Chen merged 1 commit into
devfrom
feat/image-quality-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 24, 2026

Copy link
Copy Markdown
Member

Why

OCR and template matching quietly fail on a blurry, washed-out or too-dark capture — the locate returns nothing and the caller can't tell a missing element from an unreadable one. image_quality measures the three things that wreck recognition and gates on them:

  • sharpness — variance of the Laplacian (low = blurry / out of focus)
  • contrast — grayscale standard deviation (low = washed out)
  • brightness — mean grayscale 0–255 (too low = dark, too high = blown out)

image_quality returns the raw metrics, is_blurry is the common one-liner, and quality_gate turns them into {passed, issues} flagging blurry / low_contrast / too_dark / too_bright so a script can pre-process or re-capture before OCR.

Design

  • Reuses visual_match._haystack_gray — source is any ndarray / path / PIL image, or the live screen when omitted (region applies to the screen grab). cv2/numpy lazily imported.
  • 5 layers wired: core → facade __all__AC_image_quality / AC_quality_gate → read-only ac_* MCP tools → Script Builder (Image). Qt-free verified.

Tests

test/unit_test/headless/test_image_quality_batch.py (cv2 via importorskip) — metric types/range, sharp-vs-blurry ordering + is_blurry, gate pass/fail with issues, dark-frame flag, tunable brightness range, the pure executor path, and 5-layer wiring. 16 passed with the img_histogram sibling.

OCR and template matching quietly fail on a blurry, washed-out or
too-dark capture, and the caller can't tell a missing element from an
unreadable one. Measure sharpness (variance of the Laplacian), contrast
(grayscale stddev) and brightness (mean), and gate on them with named
issues (blurry / low_contrast / too_dark / too_bright) so a script can
pre-process or re-capture before OCR. Reuses visual_match's grayscale
loader; cv2/numpy lazily imported.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 22 complexity · 0 duplication

Metric Results
Complexity 22
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit debb186 into dev Jun 24, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/image-quality-batch branch June 24, 2026 06:30
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant