def add_label_outline(self, label, outline):
"""
Save the given label to file.
Argument label can be a color or a string
Argument outline is list of pairs of (x, y) coordinates of a polygon
If the length of outline is less than 2, this does nothing.
"""
if isinstance(label, str):
label = next(c for c, nm in self.names.items() if nm == label)
assert(isinstance(label, tuple) and len(label) == 4) # Colors are tuples of 4 ints
if len(outline) < 2:
return # Already done.
im = Image.open(self.current_label)
# Draw the polygon
draw = ImageDraw.Draw(im)
draw.polygon(outline, fill=label)
del draw
im.save(self.current_label)
评论列表
文章目录