test_doc_preprocessor.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytest
  2. from paddleocr import DocPreprocessor
  3. from ..testing_utils import (
  4. TEST_DATA_DIR,
  5. check_simple_inference_result,
  6. check_wrapper_simple_inference_param_forwarding,
  7. )
  8. @pytest.fixture(scope="module")
  9. def ocr_engine() -> DocPreprocessor:
  10. return DocPreprocessor()
  11. @pytest.mark.parametrize(
  12. "image_path",
  13. [
  14. TEST_DATA_DIR / "book_rot180.jpg",
  15. ],
  16. )
  17. def test_predict(ocr_engine: DocPreprocessor, image_path: str) -> None:
  18. """
  19. Test PaddleOCR's doc preprocessor functionality.
  20. Args:
  21. ocr_engine: An instance of `DocPreprocessor`.
  22. image_path: Path to the image to be processed.
  23. """
  24. result = ocr_engine.predict(str(image_path))
  25. check_simple_inference_result(result)
  26. res = result[0]
  27. assert res["angle"] in {0, 90, 180, 270, -1}
  28. assert res["rot_img"] is not None
  29. assert res["output_img"] is not None
  30. @pytest.mark.parametrize(
  31. "params",
  32. [
  33. {"use_doc_orientation_classify": False},
  34. {"use_doc_unwarping": False},
  35. ],
  36. )
  37. def test_predict_params(
  38. monkeypatch,
  39. ocr_engine: DocPreprocessor,
  40. params: dict,
  41. ) -> None:
  42. check_wrapper_simple_inference_param_forwarding(
  43. monkeypatch,
  44. ocr_engine,
  45. "paddlex_pipeline",
  46. "dummy_path",
  47. params,
  48. )