result.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. from ...common.result import BaseCVResult, JsonMixin
  16. from ..pp_shitu_v2.result import draw_box
  17. class FaceRecResult(BaseCVResult):
  18. def _to_img(self):
  19. """apply"""
  20. boxes = [
  21. {
  22. "coordinate": box["coordinate"],
  23. "label": box["labels"][0] if box["labels"] is not None else "Unknown",
  24. "score": box["rec_scores"][0] if box["rec_scores"] is not None else 0,
  25. }
  26. for box in self["boxes"]
  27. ]
  28. image = draw_box(self["input_img"][..., ::-1], boxes)
  29. return {"res": image}
  30. def _to_str(self, *args, **kwargs):
  31. data = copy.deepcopy(self)
  32. data.pop("input_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)