我一直在尝试截取屏幕截图并找到特定颜色的每个 x、y 坐标。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<details>
<summary>Details</summary>
Something small enough to escape casual notice.
</details>
运行代码时,我收到一个坐标,然后收到一条错误消息。
from PIL import ImageGrab
import numpy as np
image = ImageGrab.grab()
indices = np.all(image == (209, 219, 221), axis=-1)
print(indices)
print(zip(indices[0], indices[1]))
怎么不行?颜色显示在屏幕上。
答案 0 :(得分:0)
我相信您在以下行中犯了错误:
indices = np.all(image == (209, 219, 221), axis=-1)
您可以直接遍历像素并获得您想要的结果:
from PIL import ImageGrab
import numpy as np
image = ImageGrab.grab()
color = (43, 43, 43)
indices = []
width, height = image.size
for x in range(width):
for y in range(height):
if image.getpixel((x, y)) == color:
indices.append((x, y))
print(indices)