I'm trying to write a Python program that detects the color of a portion of the screen and puts it in a conditional. The easiest way, I would think, would be to detect the color underneath the cursor (which would work perfectly with my program), but I can't find many up-to-date resources on that. I would like to be able to have the RGB, HEX, or some other type of value in a variable. Some ways that would work for my program: detecting the color under the cursor, detecting the color of a certain pixel, or detecting the color of a portion of pixels. Thanks for your help!
Asked
Active
Viewed 210 times
0
-
Which operating system are you using? – mkrieger1 Aug 03 '20 at 22:31
-
1PyAutoGUI can do that - https://blog.wizardsoftheweb.pro/quickly-detect-cursor-position-and-color/#myfirstcursorposition ; search "Detecting color under the cursor" in that article. – TessellatingHeckler Aug 03 '20 at 22:35
-
The easiest way would be more around the mouse since you need to know what pixel to look at. Will the screen had different quadrants, or will the entire screen be one color? https://stackoverflow.com/questions/22647120/return-rgb-color-of-image-pixel-under-mouse-tkinter https://rosettacode.org/wiki/Color_of_a_screen_pixel#Python – Ron Aug 03 '20 at 22:35
-
1Does this answer your question? [Get RGB value from screen pixels with python](https://stackoverflow.com/questions/42636933/get-rgb-value-from-screen-pixels-with-python) (the question itself is the answer to your question) – mkrieger1 Aug 03 '20 at 22:37
-
https://stackoverflow.com/questions/3800458/quickly-getting-the-color-of-some-pixels-on-the-screen-in-python-on-windows-7 – Peter Wood Aug 03 '20 at 22:41
-
https://pyautogui.readthedocs.io/en/latest/screenshot.html#pixel-matching. You can take screenshot and use PIL to load that screenshot as numpy array. – Vishesh Mangla Aug 03 '20 at 22:43