I'm on ubuntu and I want to check every 0.1sec the color of a specific pixel on my screen. How can I do that?
I know about PIL but this would need a full screenshot every 0.1sec just for one single pixel.
Then I found this method using ctypes.windll : Faster method of reading screen pixel in Python than PIL?
But this wont work because I'm not on Windows. Any other idea?
Edit: Solved thanks to b_c
from Xlib import display, X
from PIL import Image #PIL
def getColor(x,y):
W, H = 1, 1
dsp = display.Display()
root = dsp.screen().root
raw = root.get_image(x, y, W, H, X.ZPixmap, 0xffffffff)
image = Image.frombytes("RGB", (W, H), raw.data, "raw", "BGRX")
print image.getpixel((0, 0))
time.sleep(0.01)
PIL and other similar programs usually allow you to specify a boundary box to grab smaller amounts
PyAutoGui allows you to take smaller sections
as referenced here https://pyautogui.readthedocs.io/en/latest/screenshot.html code such as
pyautogui.screenshot(region=(0,0, 300, 400))
could be useful
https://pillow.readthedocs.io/en/4.2.x/reference/Image.html
could be useful as well, bbox
allows you to only observe a small area.
User contributions licensed under CC BY-SA 3.0