Matthias Bisping 94e9210faf Refactoring
Various
2023-01-09 11:21:43 +01:00

29 lines
742 B
Python

import json
from cv_analysis.utils.rectangle import Rectangle
def box_to_rectangle(box):
x, y, w, h = box
return Rectangle(x, y, x + w, y + h)
def rectangle_to_box(rectangle):
return [rectangle.x1, rectangle.y1, rectangle.width, rectangle.height]
class RectangleJSONEncoder(json.JSONEncoder):
def __init__(self, *args, **kwargs):
json.JSONEncoder.__init__(self, *args, **kwargs)
self._replacement_map = {}
def default(self, o):
if isinstance(o, Rectangle):
return {"x1": o.x1, "x2": o.x2, "y1": o.y1, "y2": o.y2}
else:
return json.JSONEncoder.default(self, o)
def encode(self, o):
result = json.JSONEncoder.encode(self, o)
return result