base.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 types import MappingProxyType
  15. from ...utils.func_register import FuncRegister
  16. from ..utils.io import ImageReader, ImageWriter
  17. from .utils.mixin import JsonMixin, ImgMixin, StrMixin
  18. class BaseResult(dict, StrMixin, JsonMixin):
  19. def __init__(self, data):
  20. super().__init__(data)
  21. self._show_func_map = {}
  22. self._show_func_register = FuncRegister(self._show_func_map)
  23. StrMixin.__init__(self)
  24. JsonMixin.__init__(self)
  25. def save_all(self, save_path):
  26. for key in self._show_func_map:
  27. func = self._show_func_map[key]
  28. if "save" in key:
  29. func(save_path=save_path)
  30. else:
  31. func()
  32. class CVResult(BaseResult, ImgMixin):
  33. def __init__(self, data):
  34. super().__init__(data)
  35. ImgMixin.__init__(self, "pillow")
  36. self._img_reader = ImageReader(backend="pillow")
  37. self._img_writer = ImageWriter(backend="pillow")
  38. self._show_func_register("save_to_img")(self.save_to_img)