Add image_quality: sharpness/contrast/brightness gate before OCR#406
Merged
Conversation
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.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 22 |
| Duplication | 0 |
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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_qualitymeasures the three things that wreck recognition and gates on them:image_qualityreturns the raw metrics,is_blurryis the common one-liner, andquality_gateturns them into{passed, issues}flaggingblurry/low_contrast/too_dark/too_brightso a script can pre-process or re-capture before OCR.Design
visual_match._haystack_gray— source is any ndarray / path / PIL image, or the live screen when omitted (regionapplies to the screen grab). cv2/numpy lazily imported.__all__→AC_image_quality/AC_quality_gate→ read-onlyac_*MCP tools → Script Builder (Image). Qt-free verified.Tests
test/unit_test/headless/test_image_quality_batch.py(cv2 viaimportorskip) — 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 theimg_histogramsibling.