Detecting colors
Lucas H.
Posted on October 2, 2019
Hey everyone! I'm currently working on a script which detects the color of a few pixels on the screen about 30-60 times a second, to detect game states (health bar), live.
I'm doing this with Python, to integrate with OBS (a recording program).
I'm pretty new to Python, I've only worked with it for very short amounts of time.
I've looked on Stackoverflow for a small while and found someone using this script:
from PIL import ImageGrab
import time
time.clock()
image = ImageGrab.grab()
for y in range(0, 100, 10):
for x in range(0, 100, 10):
color = image.getpixel((x, y))
print(time.clock())
[Source]
Here, they use the 'for' loop in Python, with variable y and x, with Imagegrab imported.
I do not understand how 'for y in range(0,100,10)', or 'for x in range [...]' works. How does this notation work? How would I customize it to fit the pixels I want to track, which are specific to only like three, all on different locations? (I don't need more, I only need to track one because one is more than enough to see the color, right?)
Thank you guys in advance for your answers, you're awesome.
-- Lucas.
Posted on October 2, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.