1
I need to identify a color in a pixel "rectangle" and return its position to save to a variable. For example, in this image, I need to detect the blue color, and when detected it returns to me the X, Y position of it.
I tried to create the following code in Python to accomplish this task, but it does not work. I searched many forums about, but I didn’t get any results. What I might be doing wrong ?
from tkinter import *
from PIL import ImageGrab
import pyautogui
running = False
def capture_screen():
global screen
screen = ImageGrab.grab()
return screen
def scanning():
if running:
screen = capture_screen
for x in range(1658, 1766):
for y in range(31, 138):
check_pixel = screen.getpixel((x, y))
print("Check pixel", check_pixel)
resolution = pyautogui.size()
print(resolution)
root.after(80, scanning)
def start():
global running
if running != True:
running = True
elif running == True:
running = False
def stop():
global running
running = False
root = Tk()
root.title("Tstes")
root.geometry("100x100")
app = Frame(root)
app.grid()
start = Button(app, text="Start Scan", command=start)
stop = Button(app, text="Stop", command=stop)
start.grid()
stop.grid()
root.after(1, scanning)
root.mainloop()