test_seal_rec.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import pytest
  2. from paddleocr import SealRecognition
  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() -> SealRecognition:
  10. return SealRecognition()
  11. @pytest.mark.parametrize(
  12. "image_path",
  13. [
  14. TEST_DATA_DIR / "seal.png",
  15. ],
  16. )
  17. def test_predict(ocr_engine: SealRecognition, image_path: str) -> None:
  18. """
  19. Test PaddleOCR's seal recognition functionality.
  20. Args:
  21. ocr_engine: An instance of `SealRecognition`.
  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]["seal_res_list"][0]
  27. assert len(res["dt_polys"]) > 0
  28. assert isinstance(res["rec_texts"], list)
  29. assert len(res["rec_texts"]) > 0
  30. for text in res["rec_texts"]:
  31. assert isinstance(text, str)
  32. @pytest.mark.parametrize(
  33. "params",
  34. [
  35. {"use_doc_orientation_classify": False, "use_doc_unwarping": False},
  36. {"use_layout_detection": False},
  37. {"layout_det_res": None},
  38. {"layout_threshold": 0.5},
  39. {"layout_nms": False},
  40. {"layout_unclip_ratio": 1.0},
  41. {"layout_merge_bboxes_mode": "large"},
  42. {"seal_det_limit_side_len": 736},
  43. {"seal_det_limit_type": "min"},
  44. {"seal_det_thresh": 0.5},
  45. {"seal_det_box_thresh": 0.6},
  46. {"seal_det_unclip_ratio": 0.5},
  47. {"seal_rec_score_thresh": 0.05},
  48. ],
  49. )
  50. def test_predict_params(
  51. monkeypatch,
  52. ocr_engine: SealRecognition,
  53. params: dict,
  54. ) -> None:
  55. check_wrapper_simple_inference_param_forwarding(
  56. monkeypatch,
  57. ocr_engine,
  58. "paddlex_pipeline",
  59. "dummy_path",
  60. params,
  61. )