in pipeline/postprocessing/fn-postprocess/util/boxes.py [0:0]
def to_dict(self, style: str = "TLHW") -> Dict[str, Real]:
"""Express the box as a (JSON serializable) dict
Arguments
---------
style : str
Some combination of characters T,L,H,W,B,R (upper- or lower-case) indicating what
properties should be included in the dict. E.g. 'TLbr' will generate a result with
{ 'Top', 'Left', 'bottom', 'right' }
"""
if not style:
return ValueError(f"Bounding box to_dict got empty style spec '{style}'")
result = {}
for prop in style:
if prop == "T":
result["Top"] = self._top
elif prop == "t":
result["top"] = self._top
elif prop == "L":
result["Left"] = self._left
elif prop == "l":
result["left"] = self._left
elif prop == "H":
result["Height"] = self._height
elif prop == "h":
result["height"] = self._height
elif prop == "W":
result["Width"] = self._width
elif prop == "w":
result["width"] = self._width
elif prop == "B":
result["Bottom"] = self._bottom
elif prop == "b":
result["bottom"] = self._bottom
elif prop == "R":
result["Right"] = self._right
elif prop == "r":
result["right"] = self._right
else:
raise ValueError(
f"Bounding box to_dict style '{style}' contained unrecognised spec '{prop}'"
)
return result