Files
second-screen/tests/helpers.py
T
2026-10-22 13:17:44 +02:00

10 lines
323 B
Python

import numpy as np
from PIL import Image
def count_colour(img: Image.Image, colour, box=None) -> int:
"""Number of pixels of `colour` in `img` (optionally only inside `box`)."""
if box is not None:
img = img.crop(box)
return int((np.asarray(img.convert("RGB")) == np.array(colour)).all(axis=2).sum())