diff --git a/perception/ocr.py b/perception/ocr.py index 376c601..27f9ce8 100644 --- a/perception/ocr.py +++ b/perception/ocr.py @@ -33,6 +33,16 @@ class OCRBox: class PaddleOCREngine: def __init__(self, **kwargs: Any) -> None: + # Device screenshots are already upright, flat digital captures, not + # photographed paper documents, so PaddleOCR's document-preprocessing + # models (orientation classification + UVDoc unwarping) have nothing + # real to correct. Left at their library defaults (True), they still + # run, geometrically warp the image, and detect/recognize text against + # that warped image, returning box coordinates that no longer line up + # with the original screenshot. Callers can still opt back in via an + # explicit kwarg. + kwargs.setdefault("use_doc_orientation_classify", False) + kwargs.setdefault("use_doc_unwarping", False) self.kwargs = kwargs self._engine: Any | None = None diff --git a/tests/test_ocr.py b/tests/test_ocr.py index 2c68a32..d3ed929 100644 --- a/tests/test_ocr.py +++ b/tests/test_ocr.py @@ -4,7 +4,24 @@ import numpy as np import pytest from core.models import Bounds -from perception.ocr import OCRBox, parse_paddle_result, run_ocr +from perception.ocr import OCRBox, PaddleOCREngine, parse_paddle_result, run_ocr + + +def test_paddle_ocr_engine_disables_doc_preprocessing_by_default() -> None: + # Screenshots are flat, upright digital captures, not photographed paper + # documents: PaddleOCR's document-unwarping preprocessing has nothing real + # to correct and instead warps the image, so detected box coordinates no + # longer line up with the original screenshot. + engine = PaddleOCREngine(lang="ch") + + assert engine.kwargs["use_doc_orientation_classify"] is False + assert engine.kwargs["use_doc_unwarping"] is False + + +def test_paddle_ocr_engine_lets_callers_override_doc_preprocessing() -> None: + engine = PaddleOCREngine(use_doc_unwarping=True) + + assert engine.kwargs["use_doc_unwarping"] is True def test_parse_paddle_result_accepts_ndarray_fields() -> None: