test_ocr.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from paddlex import create_pipeline
  15. pipeline = create_pipeline(pipeline="OCR")
  16. output = pipeline.predict(
  17. "./test_samples/general_ocr_002.png",
  18. use_doc_orientation_classify=False,
  19. use_doc_unwarping=False,
  20. use_textline_orientation=False,
  21. )
  22. # output = pipeline.predict(
  23. # "./test_samples/general_ocr_002.png",
  24. # use_doc_orientation_classify=False,
  25. # use_doc_unwarping=False,
  26. # use_textline_orientation=False,
  27. # text_rec_score_thresh = 0.5
  28. # )
  29. # output = pipeline.predict(
  30. # "./test_samples/general_ocr_002.png",
  31. # use_doc_orientation_classify=False,
  32. # use_doc_unwarping=False,
  33. # use_textline_orientation=False,
  34. # text_det_unclip_ratio=3.0,
  35. # text_det_limit_side_len=1920
  36. # )
  37. # output = pipeline.predict(
  38. # "./test_samples/general_ocr_002.png",
  39. # use_doc_orientation_classify=True,
  40. # use_doc_unwarping=True,
  41. # use_textline_orientation=False
  42. # )
  43. # output = pipeline.predict(
  44. # "./test_samples/general_ocr_003.jpg",
  45. # use_doc_orientation_classify=False,
  46. # use_doc_unwarping=False,
  47. # use_textline_orientation=False
  48. # )
  49. # output = pipeline.predict(
  50. # "./test_samples/general_ocr_003.jpg",
  51. # use_doc_orientation_classify=False,
  52. # use_doc_unwarping=False,
  53. # use_textline_orientation=True
  54. # )
  55. # output = pipeline.predict(
  56. # "./test_samples/general_ocr_002_rotate_90.png",
  57. # use_doc_orientation_classify=False,
  58. # use_doc_unwarping=False,
  59. # use_textline_orientation=False
  60. # )
  61. # output = pipeline.predict(
  62. # "./test_samples/general_ocr_002_rotate_90.png",
  63. # use_doc_orientation_classify=False,
  64. # use_doc_unwarping=False,
  65. # use_textline_orientation=True
  66. # )
  67. # output = pipeline.predict(
  68. # "./test_samples/general_ocr_002.png")
  69. # output = pipeline.predict("./test_samples/财报1.pdf")
  70. for res in output:
  71. print(res)
  72. res.print()
  73. res.save_to_img("./output")
  74. res.save_to_json("./output")