result.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. import copy
  15. import numpy as np
  16. from ...common.result import BaseCVResult, JsonMixin
  17. class DocTrResult(BaseCVResult):
  18. """
  19. Result class for DocTr, encapsulating the output of a document image processing task.
  20. Attributes:
  21. (inherited from BaseCVResult): Any attributes defined in the base class.
  22. Methods:
  23. _to_img(self) -> np.ndarray:
  24. Converts the stored image result to a numpy array.
  25. """
  26. def _to_img(self) -> np.ndarray:
  27. result = np.array(self["doctr_img"])
  28. return {"res": result}
  29. def _to_str(self, *args, **kwargs):
  30. data = copy.deepcopy(self)
  31. data.pop("input_img")
  32. data["doctr_img"] = "..."
  33. return JsonMixin._to_str(data, *args, **kwargs)
  34. def _to_json(self, *args, **kwargs):
  35. data = copy.deepcopy(self)
  36. data.pop("input_img")
  37. return JsonMixin._to_json(data, *args, **kwargs)