seal_rec.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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 pathlib import Path
  15. from .base import BaseResult, CVResult
  16. class SealOCRResult(CVResult):
  17. """SealOCRResult"""
  18. def save_to_img(self, save_path):
  19. if not save_path.lower().endswith((".jpg", ".png")):
  20. input_path = self["input_path"]
  21. save_path = Path(save_path) / f"{Path(input_path).stem}"
  22. else:
  23. save_path = Path(save_path).stem
  24. layout_save_path = f"{save_path}_layout.jpg"
  25. layout_result = self["layout_result"]
  26. layout_result.save_to_img(layout_save_path)
  27. for idx, seal_result in enumerate(self["ocr_result"]):
  28. ocr_save_path = f"{save_path}_{idx}_seal_ocr.jpg"
  29. seal_result.save_to_img(ocr_save_path)