MediaBoundingBox.py 737 B

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