Create a bounding box from a string or other detection object. Args: obj (Box or string, optional): Bounding box object to copy attributes from or string to deserialize
(cls, obj=None)
| 29 | |
| 30 | @classmethod |
| 31 | def create(cls, obj=None): |
| 32 | """ Create a bounding box from a string or other detection object. |
| 33 | |
| 34 | Args: |
| 35 | obj (Box or string, optional): Bounding box object to copy attributes from or string to deserialize |
| 36 | """ |
| 37 | instance = cls() |
| 38 | |
| 39 | if obj is None: |
| 40 | return instance |
| 41 | |
| 42 | if isinstance(obj, str): |
| 43 | instance.deserialize(obj) |
| 44 | elif isinstance(obj, Box): |
| 45 | instance.class_label = obj.class_label |
| 46 | instance.object_id = obj.object_id |
| 47 | instance.x_top_left = obj.x_top_left |
| 48 | instance.y_top_left = obj.y_top_left |
| 49 | instance.width = obj.width |
| 50 | instance.height = obj.height |
| 51 | else: |
| 52 | raise TypeError(f'Object is not of type Box or not a string [obj.__class__.__name__]') |
| 53 | |
| 54 | return instance |
| 55 | |
| 56 | def __eq__(self, other): |
| 57 | # TODO: refactor -> use almost equal for floats |
no test coverage detected