-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screen grab.py
47 lines (40 loc) · 1.15 KB
/
Screen grab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import cv2
import numpy as np
from PIL import ImageGrab
import time
import pyautogui as pag
##countdown from 3
for i in list(range(3))[::-1]:
print(i+1)
time.sleep(1)
##entering keystrokes as inputs into heboris ue exe
##pag.keyDown('z')
##pag.keyUp('z')
##pag.keyDown('left')
##pag.keyUp('left')
##pag.keyDown('right')
##pag.keyUp('right')
##pag.keyDown('up')
##pag.keyUp('up')
##pag.keyDown('down')
##pag.keyUp('down')
##pag.keyDown('z')
##pag.keyUp('z')
##pag.keyDown('z')
##pag.keyUp('z')
##manipulating the recording of the screen to make data simpler
def process(screen):
processed_img = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
processed_img = cv2.inRange(processed_img, lowerb=20, upperb=255)
return processed_img
##recording an area of the screen
last_time = time.time()
while(True):
screen = np.array(ImageGrab.grab(bbox=(450, 40, 830, 855)))
screen2 = process(screen)
#print('Loop time:', time.time()-last_time) #shows how fast the program is running
last_time = time.time()
cv2.imshow('Processed Tetris', screen2) #creates a window
if cv2.waitKey(25) and 0xFF == ord('q'):
cv2.destroyAllWindows()
break