def convert_traxregion(region: TraxRegion) -> Region: if region.type == TraxRegion.RECTANGLE: x, y, width, height = region.bounds() return Rectangle(x, y, width, height) elif region.type == TraxRegion.POLYGON: return Polygon(list(region)) elif region.type == TraxRegion.MASK: return Mask(region.array(), region.offset(), optimize=True) return None
def test_convert_region(self): convert_region(Rectangle(0, 0, 10, 10)) convert_region(Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])) convert_region(Mask(np.ones((100, 100), dtype=np.uint8)))