test(ocr): add resilience tests for tiny image and unexpected exception propagation
Add test for 1×1 image (sub-tile-size) resilience and narrow preprocess_page fallback from except Exception to (cv2.error, ValueError, MemoryError) so programming errors propagate instead of being silently swallowed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #255.
This commit is contained in:
@@ -16,7 +16,8 @@ CLAHE_TILE_SIZE = int(os.environ.get("OCR_CLAHE_TILE_SIZE", "8"))
|
||||
def preprocess_page(image: Image.Image) -> Image.Image:
|
||||
"""Apply CLAHE + grayscale + Gaussian blur to improve OCR quality on aged documents.
|
||||
|
||||
Falls back silently to the original image if any step fails.
|
||||
Falls back silently to the original image if cv2, numpy, or memory errors occur.
|
||||
Unexpected exceptions (programming errors) are allowed to propagate.
|
||||
"""
|
||||
try:
|
||||
img_array = np.array(image)
|
||||
@@ -40,7 +41,7 @@ def preprocess_page(image: Image.Image) -> Image.Image:
|
||||
del blurred
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
except (cv2.error, ValueError, MemoryError) as e:
|
||||
logger.warning(
|
||||
"preprocess_page failed (falling back to original): %s: %s",
|
||||
type(e).__name__,
|
||||
|
||||
Reference in New Issue
Block a user