test_ocr.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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=True,
  19. use_doc_unwarping=True,
  20. use_textline_orientation=True,
  21. )
  22. # output = pipeline.predict(
  23. # "./test_samples/general_ocr_002.png",
  24. # use_doc_orientation_classify=True,
  25. # use_doc_unwarping=True,
  26. # use_textline_orientation=False,
  27. # )
  28. # output = pipeline.predict(
  29. # "./test_samples/general_ocr_002.png",
  30. # use_doc_orientation_classify=True,
  31. # use_doc_unwarping=False,
  32. # use_textline_orientation=True,
  33. # )
  34. # output = pipeline.predict(
  35. # "./test_samples/general_ocr_002.png",
  36. # use_doc_orientation_classify=True,
  37. # use_doc_unwarping=False,
  38. # use_textline_orientation=False,
  39. # )
  40. # output = pipeline.predict(
  41. # "./test_samples/general_ocr_002.png",
  42. # use_doc_orientation_classify=False,
  43. # use_doc_unwarping=True,
  44. # use_textline_orientation=True,
  45. # )
  46. # output = pipeline.predict(
  47. # "./test_samples/general_ocr_002.png",
  48. # use_doc_orientation_classify=False,
  49. # use_doc_unwarping=True,
  50. # use_textline_orientation=False,
  51. # )
  52. # output = pipeline.predict(
  53. # "./test_samples/general_ocr_002.png",
  54. # use_doc_orientation_classify=False,
  55. # use_doc_unwarping=False,
  56. # use_textline_orientation=True,
  57. # )
  58. # output = pipeline.predict(
  59. # "./test_samples/general_ocr_002.png",
  60. # use_doc_orientation_classify=False,
  61. # use_doc_unwarping=False,
  62. # use_textline_orientation=False,
  63. # )
  64. # output = pipeline.predict("./test_samples/财报1.pdf")
  65. for res in output:
  66. print(res)
  67. res.save_to_img("./output")
  68. res.save_to_json("./output/res.json")