-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmss_screen_test.py
58 lines (48 loc) · 1.5 KB
/
mss_screen_test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import time
import cv2
import mss
import numpy as np
# the region of the screen with all 5 fret keys
reg = {
"top": 480,
"left": 215,
"width": 370,
"height": 80
}
def screen_record_efficient():
fps = 0
sct = mss.mss()
last_time = time.time()
while time.time() - last_time < 1:
img = np.asarray(sct.grab(reg))
fps += 1
# cv2.imshow(title, img)
# if cv2.waitKey(25) & 0xFF == ord("q"):
# cv2.destroyAllWindows()
# break
cv2.imwrite("test.jpg", img)
return fps, img
def speed_test_alt():
sct = mss.mss()
start_time = time.time()
print("starting...")
while time.time() - start_time < 10:
start = time.perf_counter()
img = np.asarray(sct.grab(reg))
inference_time = time.perf_counter() - start
print('%.1fms' % (inference_time * 1000))
time.sleep(0.25)
def test_numpy_copy():
# testing speeds of adding 6 columns to screen grab to make it square
import random
for _i in range(20):
small = np.ones((74, 80), dtype=np.float32)
big = np.zeros((80, 80), dtype=np.float32)
start = time.perf_counter()
big[0:74, 0:80] = small
# essentially fractions of a nano second...
print('%.1fms' % ((time.perf_counter() - start) * 1000))
if __name__ == '__main__':
#_fps, img = screen_record_efficient()
speed_test_alt()
#test_numpy_copy()