Python Forum
Learning pixel change detection in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Learning pixel change detection in Python (/thread-13948.html)



Learning pixel change detection in Python - Hallucin88 - Nov-07-2018

I decided to learn how to code with Python with a specific goal in mind and could use some help with learning resources towards that goal.

Using AutoHotKey I managed to write a little script with a GUI that loads up an image from a directory and then uses ImageSearch in a loop to scan an active window for the previously loaded .png. If detected it acts with a combination of hotkeys or mouse movement/clicks.

Now I would like to rewrite that script in Python, but I was unable to find any equivalent to ImageSearch that AutoHotKey uses. AHK has also another way of doing the job, PixelSearch. With PixelSearch I was able to select a region of an active window and it would scan the region for any change in the pixels, allowing for the script to act with hotkeys/mouse clicks.

How would I go about coding this in Python? Or maybe theres a different way to detect area of the screen changes?

Please don't be too harsh Angel


RE: Learning pixel change detection in Python - nilamo - Nov-07-2018

pyscreenshot looks cross platform: https://github.com/ponty/pyscreenshot

There's nothing builtin, because getting random pixels of a display is a very weird thing to do. What is it you're trying to accomplish? There might be a "better" way than image scraping yourself lol


RE: Learning pixel change detection in Python - Hallucin88 - Nov-07-2018

(Nov-07-2018, 08:03 PM)nilamo Wrote: pyscreenshot looks cross platform: https://github.com/ponty/pyscreenshot There's nothing builtin, because getting random pixels of a display is a very weird thing to do. What is it you're trying to accomplish? There might be a "better" way than image scraping yourself lol

Thank you, PIL looks like a tool for the job. I can think of a few uses for this, the main one could be games. For example if I'm selling an item in an online game, my PC has to be running in order for the shop to be online. So instead of leaving my PC running all night every night, I could detect whether someone bought an item and the little program could proceed to shut down my PC.

Thanks again :)

(Nov-07-2018, 08:46 PM)Hallucin88 Wrote:
(Nov-07-2018, 08:03 PM)nilamo Wrote: pyscreenshot looks cross platform: https://github.com/ponty/pyscreenshot There's nothing builtin, because getting random pixels of a display is a very weird thing to do. What is it you're trying to accomplish? There might be a "better" way than image scraping yourself lol
Thank you, PIL looks like a tool for the job. I can think of a few uses for this, the main one could be games. For example if I'm selling an item in an online game, my PC has to be running in order for the shop to be online. So instead of leaving my PC running all night every night, I could detect whether someone bought an item and the little program could proceed to shut down my PC. Thanks again :)

Actually after reading a bit more on PIL I don't think it's possible to actively scan for a change of pixels in a region. It seems that PIL can do everything to an image, but not to what is displayed in real time. Hm...