Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在屏幕上查找颜色_Python_Image_Colors_Python Imaging Library - Fatal编程技术网

Python 在屏幕上查找颜色

Python 在屏幕上查找颜色,python,image,colors,python-imaging-library,Python,Image,Colors,Python Imaging Library,我目前正在尝试检测屏幕上的颜色,例如黑屏上的白色像素。 我正在使用ImageGrab.grab()抓取图像,但无法搜索颜色。我试过: for x in range(0, 300): for y in range(0, 460): px = image.getpixel((x, y)) if px[0] == 255 and px[1] == 255 and px[2] == 255:

我目前正在尝试检测屏幕上的颜色,例如黑屏上的白色像素。 我正在使用
ImageGrab.grab()
抓取图像,但无法搜索颜色。我试过:

 for x in range(0, 300):
            for y in range(0, 460):
                px = image.getpixel((x, y))
                if px[0] == 255 and px[1] == 255 and px[2] == 255:
                    print(x)
                    print(y)
但这对我来说并不奏效。我在cv2上看到了一些东西,但他只显示了一点点代码,所以我无法复制他的代码。
谢谢:)

在循环像素之前,您的图像是否已转换为RGB?假设您使用的是PIL,它是这样的:
image.convert('RGB')
,其中image是您的
image
对象。您能否发布您正在加载的确切图像,以及如何打开它?可能与此有关。