forked from anywhere2go/auto_player
-
Notifications
You must be signed in to change notification settings - Fork 72
/
test.py
executable file
·70 lines (50 loc) · 1.75 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
# !pip install image
# !pip install opencv-python
# !pip install pyscreenshot
import numpy as np
from time import time
resolutions = [
(0, 0, 100,100),(0, 0, 200,100),
(0, 0, 200,200),(0, 0, 400,200),
(0, 0, 400,400),(0, 0, 800,400)
]
import numpy as np
import pyscreenshot as ImageGrab
import cv2
def show(nparray):
import cv2
cv2.imshow('window',cv2.cvtColor(nparray, cv2.COLOR_BGR2RGB))
# key controls in a displayed window
# if cv2.waitKey(25) & 0xFF == ord('q'):
# cv2.destroyAllWindows()
def mss_test(shape) :
average = time()
import mss
sct = mss.mss()
mon = {"top": shape[0], "left": shape[1], "width": shape[2]-shape[1], "height": shape[3]-shape[0]}
for _ in range(5):
printscreen = np.asarray(sct.grab(mon))
average_ms = int(1000*(time()-average)/5.)
return average_ms, printscreen.shape
def pil_test(shape) :
average = time()
from PIL import ImageGrab
for _ in range(5):
printscreen = np.array(ImageGrab.grab(bbox=shape))
average_ms = int(1000*(time()-average)/5.)
return average_ms, printscreen.shape
def pyscreenshot_test(shape):
average = time()
import pyscreenshot as ImageGrab
for _ in range(5):
printscreen = np.asarray( ImageGrab.grab(bbox=shape) )
average_ms = int(1000*(time()-average)/5.)
return average_ms, printscreen.shape
named_function_pair = zip("mss_test,pil_test,pyscreenshot_test".split(","),
[mss_test,pil_test,pyscreenshot_test])
for name,function in named_function_pair:
results = [ function(res) for res in resolutions ]
print("Speed results for using",name)
for res,result in zip(resolutions,results) :
speed,shape = result
print(res,"took",speed,"ms, produced shaped",shape)