result.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. import os
  15. from pathlib import Path
  16. class SealRecognitionResult(dict):
  17. """Seal Recognition Result"""
  18. def __init__(self, data) -> None:
  19. """Initializes a new instance of the class with the specified data."""
  20. super().__init__(data)
  21. def save_results(self, save_path: str) -> None:
  22. """Save the layout parsing results to the specified directory.
  23. Args:
  24. save_path (str): The directory path to save the results.
  25. """
  26. if not os.path.isdir(save_path):
  27. return
  28. img_id = self["img_id"]
  29. layout_det_res = self["layout_det_res"]
  30. if len(layout_det_res) > 0:
  31. save_img_path = Path(save_path) / f"layout_det_result_img{img_id}.jpg"
  32. layout_det_res.save_to_img(save_img_path)
  33. input_params = self["input_params"]
  34. if input_params["use_doc_preprocessor"]:
  35. save_img_path = Path(save_path) / f"doc_preprocessor_result_img{img_id}.jpg"
  36. self["doc_preprocessor_res"].save_to_img(save_img_path)
  37. for sno in range(len(self["seal_res_list"])):
  38. seal_res = self["seal_res_list"][sno]
  39. seal_region_id = seal_res["seal_region_id"]
  40. save_img_path = (
  41. Path(save_path) / f"seal_res_img{img_id}_region{seal_region_id}.jpg"
  42. )
  43. seal_res.save_to_img(save_img_path)
  44. return