warp.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 numpy as np
  15. import copy
  16. import json
  17. from ...utils import logging
  18. from .base import BaseResult
  19. class DocTrResult(BaseResult):
  20. def __init__(self, data):
  21. super().__init__(data)
  22. # We use opencv backend to save both numpy arrays
  23. self._img_writer.set_backend("opencv")
  24. def _get_res_img(self):
  25. doctr_img = np.array(self["doctr_img"])
  26. return doctr_img
  27. def print(self, json_format=True, indent=4, ensure_ascii=False):
  28. str_ = copy.deepcopy(self)
  29. del str_["doctr_img"]
  30. if json_format:
  31. str_ = json.dumps(str_, indent=indent, ensure_ascii=ensure_ascii)
  32. logging.info(str_)