in src/co_op_translator/utils/vision/image_utils.py [0:0]
def get_average_color(image, bounding_box):
"""
Get the average color of a bounding box area in the image.
Args:
image (PIL.Image.Image): The image object.
bounding_box (list): The bounding box coordinates.
Returns:
tuple: The average color (R, G, B).
"""
mask = Image.new("L", image.size, 0)
draw = ImageDraw.Draw(mask)
pts = [
(bounding_box[i], bounding_box[i + 1]) for i in range(0, len(bounding_box), 2)
]
draw.polygon(pts, fill=255)
stat = ImageStat.Stat(image, mask)
avg_color = tuple(int(x) for x in stat.mean[:3])
return avg_color