[英]read an array of pixel values python
I would like to take a screenshot with a certain range of the screen, and then I would like to check the pixel values of certain lines (eg x_axis from 400 to 800). 我想在屏幕的特定范围内截取屏幕截图,然后我想检查某些行的像素值(例如x_axis从400到800)。 I tried multiple ways like the imagegrab, gdi32.GetPixel and some more.
我尝试了多种方式,例如imagegrab,gdi32.GetPixel等。 It seems reading pixels values take a lot of time, so I even tried converting it into a list, something like this
似乎读取像素值需要花费很多时间,所以我什至尝试将其转换为列表,像这样
im = ImageGrab.grab(box)
pixels = list(im .getdata())
Even this does not seem fast. 即使这样看起来也不快。 Is there something I'm doing wrong?
我做错了什么吗?
ImageGrab
returns pixels in PIL format (the Python Imaging Library: http://effbot.org/imagingbook/image.htm ), and .getdata()
already returns the pixels as a sequence. ImageGrab
以PIL格式返回像素(Python Imaging Library: http : .getdata()
),而.getdata()
已将像素作为序列返回。 By wrapping it in list()
again you are doing the same (expensive) operation twice. 通过将其再次包装在
list()
,您将执行两次相同的(昂贵的)操作。 You can just do: 您可以这样做:
im = ImageGrab.grab(box)
pixels = im.getdata()
And iterate through your pixels in your favorite way. 并以自己喜欢的方式遍历像素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.