【问题标题】:Search image for color. Return X, Y搜索图像的颜色。返回 X, Y
【发布时间】:2012-01-14 13:04:25
【问题描述】:

我一直在寻找一种方法来查找图像中的特定颜色(屏幕截图),并返回颜色的位置 (x,y)。我进行了一些尝试,但没有进行适当的搜索。结果应该是找到具有该颜色的第一个像素。

我认为 PIL 可能会有所帮助。所以我尝试了这样的事情,现在的问题是它返回每个位置,用那种颜色找到:

固定:

def FindColor(r,g,b):
    image = ImageGrab.grab()
    for x in range(1, 400):
        for y in range(1,400):
            px = image.getpixel((x, y))
            if px[0] == r and px[1] == g and px[2] == b:
                return(x,y)

而且,我需要用图片的宽度/高度替换循环范围。

【问题讨论】:

    标签: python image colors find python-imaging-library


    【解决方案1】:

    return 第一次匹配的结果,而不是继续循环。

    【讨论】:

    • 当然,我忘了我可以像使用返回语句那样简单地做到这一点。泰!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 2012-01-18
    • 2020-10-10
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    相关资源
    最近更新 更多