Python Forum

Full Version: Button Press When Pixel Color Changes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to scripting with python and I just need some help with something that is simple.
All I need to do is a button press or mouse click whenever a pixel is a certain color.
Ex. if pixel 960,540 is any value of blue, press spacebar or
if pixel 960,540 is a value yellow, click at 0,0

I already have code that feeds a live stream of one quarter of my screen:

import cv2
import numpy as np
import time
from PIL import ImageGrab


last_time = time.time ()
while(True):
        screen = np.array(ImageGrab.grab(bbox=(0,540, 960, 1080)))
        #printscreen_numpy =  np.array(printscreen_pil.getdata(),dtype='uint8')

        print('Loop took {} seconds'.format(time.time()-last_time))
        last_time = time.time()
        cv2.imshow('window', cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
Just need help or be given any sources that can help me. Thanks in advanced.