-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.py
114 lines (90 loc) · 2.38 KB
/
tool.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from PIL import Image, ImageOps
import numpy as np
import wscreenshot
import time
import cv2
import os
def record():
dest_dir = 'screenshots5'
win_text = '升级角色版'
ws = None
while True:
try:
ws = wscreenshot.Screenshot(win_text)
break
except Exception:
time.sleep(0.5)
continue
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
while True:
img = ws.screenshot()
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.imwrite(os.path.join(dest_dir, str(int(time.time() * 10)) + '.bmp'), img)
time.sleep(0.5)
def get_template1():
img = np.array(Image.open('screenshots2/16442133829.bmp'))
height = 16
width = 22
x0 = 343
y0 = 796
stride = 24
for i in range(39):
x = x0 + int(i * stride)
y = y0
rect = img[y:y+height, x: x+width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
def get_template1a():
img = np.array(Image.open('screenshots6/1645289775.2096496.bmp'))
height = 8
width = 22
x0 = 199
y0 = 792
stride = 24
for i in range(45):
x = x0 + int(i * stride)
y = y0
rect = img[y:y+height, x: x+width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
def get_template2():
img = np.array(Image.open('screenshots2/16442133829.bmp'))
height = 18
width = 22
x0 = 343
y0 = 813
stride = 24
for i in range(39):
x = x0 + int(i * stride)
y = y0
rect = img[y:y+height, x: x+width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
def get_template3():
img = np.array(Image.open('digits.bmp'))
height = 11
width = 6
x0 = 3
y0 = 2
stride = 12
for i in range(16):
x = x0 + int(i * stride)
y = y0
rect = img[y:y+height, x: x+width]
char_img = Image.fromarray(rect)
char_img.save('s' + str(i) + '.bmp')
def get_template4():
img = np.array(Image.open('screenshots3/16442123931.bmp'))
height = 17
width = 13
x0 = 108
y0 = 944
stride = 21
for i in range(2):
x = x0 + int(i * stride)
y = y0
rect = img[y:y+height, x: x+width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
get_template1a()