MediaBoundingBox.py 777 B

12345678910111213141516171819202122232425
  1. from pycs.database.Result import Result
  2. #pylint: disable=too-few-public-methods
  3. class MediaBoundingBox:
  4. """
  5. A bounding box defined by it's upper left corner coordinates plus width and height. All those
  6. values are normalized. A label and a frame (for videos) are optional.
  7. """
  8. def __init__(self, result: Result):
  9. self.x = result.data['x']
  10. self.y = result.data['y']
  11. self.w = result.data['w']
  12. self.h = result.data['h']
  13. self.label = result.label
  14. self.frame = result.data['frame'] if 'frame' in result.data else None
  15. def serialize(self) -> dict:
  16. """
  17. serialize all object properties to a dict
  18. :return: dict
  19. """
  20. return dict({'type': 'bounding-box'}, **self.__dict__)