r/pythonhelp • u/[deleted] • Sep 17 '22
Active screen recording.
Hello! I am trying to get a script that will actively view a changing screen while searching for certain colors or textures. I am very open to doing my own research but thought to come here for ideas first. Ultimately what I'd like Is a script that locates the "texture" some time multiples will be on screen, brings the mouse over it and interacts with a key press. Any suggestions?
2
Upvotes
1
u/AmongstYou666 Sep 17 '22
import timeimport numpy as npimport mss, cv2, os, sysimport pygameimport pyautogui as pyfrom Xlib.display import Displaywith mss.mss() as sct:monitor = sct.monitors[1]pygame.init()info = pygame.display.Info()max_w = info.current_w*2max_h = info.current_h_display = Display(os.environ['DISPLAY'])def colorRange(x, y):RGB = []RGB.append(myGetPixel(x,y))py.moveTo(x+20, y+20, 1)RGB.append(myGetPixel(x,y))matchThis = np.array(RGB)RGBrange = np.sort(matchThis.T)print(RGBrange, x, y)return(RGBrange)def colorMatch(AR):TFresult = Truefor i in range(3):TFresult = TFresult and (AR[i] in range(RGBrange[i][0],RGBrange[i][1]))return(TFresult)def mousexy():coord = _display.screen().root.query_pointer()._data#print ('Running... \ncoords {}'.format(coord))x = coord['root_x']y = coord['root_y']return (x, y)def passArray(AR = []): #pass array of variablesprint(len(AR), AR)def myGetPixel(x,y):bbox = (x, y, x+1, y+1)img = np.array(sct.grab(bbox))np.array(img)#return RGBreturn ([img[0][0][0],img[0][0][1],img[0][0][2]])