Ibr*_*del 3 python python-imaging-library
我真的很难理解如何使用 PIL 操作图像。我试图返回匹配某种颜色的所有像素的 x 和 y 坐标。所以在伪代码中:
img = ImageGrab.grab(bbox)
pixels = img.getdata()
for i in range(len(pixels)):
if pixels[i] == (255, 0, 0, 255) # red for example:
coords.append(pixels[i].x)
coords.append(pixels[i].y)
Run Code Online (Sandbox Code Playgroud)
我只是不知道如何在附加 x 和 y 的最后一点做。有这个功能吗?
谢谢!
像这样:
from PIL import ImageGrab
img = ImageGrab.grab()
pixels = img.load()
width, height = img.size
coords = []
for x in range(width):
for y in range(height):
if pixels[x, y] == (255, 0, 0):
coords.append((x, y))
Run Code Online (Sandbox Code Playgroud)