-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
140 lines (126 loc) · 4.97 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import pyautogui
import cv2
import numpy as np
import time
def rgbdis(p1, p2):
dis = sum((p1 - p2) ** 2)
return dis
def metrix_create(step, parameter):
sx = parameter[0]
sy = parameter[1]
l = parameter[2]
start_point = [sx, sy]
x = []
y = []
c_x = []
c_y = []
for i in range(step+1):
if i == 0:
x.append(start_point[0])
y.append(start_point[1])
else:
sx += l / step
sy += l / step
x.append(sx)
y.append(sy)
c_x.append(int(np.floor(x[i-1] + (x[i] - x[i-1]) / 2)))
c_y.append(int(np.floor(y[i-1] + (y[i] - y[i-1]) / 2)))
return c_x, c_y
def click_operation(cord):
x = cord[0]
y = cord[1]
time.sleep(0)
pyautogui.moveTo(x, y)
pyautogui.click()
def find_diff(v):
diff_m = []
diff_sum = []
for i in v:
diff_sum.append(sum(i[0]))
average = sum(diff_sum)/len(diff_sum)
for i in v:
diff_m.append((sum(i[0])-average)**2)
if max(np.array(diff_m)) < 1:
cor = 0
else:
diff_index = np.argmax(np.array(diff_m))
cor = [v[diff_index][1], v[diff_index][2]]
return cor
if __name__ == '__main__':
parameter = [358, 471, 625, 625]
step_l = [2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8]
num = 0
cx_l = [[514, 826], [462, 670, 878], [436, 592, 748, 904], [420, 545, 670, 795, 920], [410, 514, 618, 722, 826, 930], [402, 491, 581, 670, 759, 849, 938], [397, 475, 553, 631, 709, 787, 865, 943], [392, 462, 531, 601, 670, 739, 809, 878, 948]]
cy_l = [[627, 939], [575, 783, 991], [549, 705, 861, 1017], [533, 658, 783, 908, 1033], [523, 627, 731, 835, 939, 1043], [515, 604, 694, 783, 872, 962, 1051], [510, 588, 666, 744, 822, 900, 978, 1056], [505, 575, 644, 714, 783, 852, 922, 991, 1061]]
while True:
if num > 15:
step = 9
else:
step = step_l[num]
image = pyautogui.screenshot(region=[358, 471, 625, 625])
img = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
c_x, c_y = metrix_create(step, parameter)
# c_x = cx_l[step - 2]
# c_y = cy_l[step - 2]
value = []
for cx in range(len(c_x)):
for cy in range(len(c_y)):
if len(c_x) > 2:
if cy != 0:
dis = rgbdis(img[c_y[cy] - parameter[1]][c_x[cx] - parameter[0]], img[c_y[cy-1] - parameter[1]][c_x[cx] - parameter[0]])
if cy > 2:
if dis > 0:
cord = [c_x[cx], c_y[cy]]
break
else:
continue
elif cy == 1:
temp_dis = dis
else:
if dis == temp_dis:
if dis == 0:
continue
else:
cord = [c_x[cx], c_y[1]]
break
else:
if dis > 0:
cord = [c_x[cx], c_y[2]]
break
else:
cord = [c_x[cx], c_y[0]]
break
else:
continue
else:
if cy != 0:
dis = rgbdis(img[c_y[cy] - parameter[1]][c_x[cx] - parameter[0]], img[c_y[cy-1] - parameter[1]][c_x[cx] - parameter[0]])
if dis > 0:
if cx == 0:
Dis = rgbdis(img[c_y[cy] - parameter[1]][c_x[cx + 1] - parameter[0]],
img[c_y[cy - 1] - parameter[1]][c_x[cx] - parameter[0]])
if Dis > 0:
cord = [c_x[cx], c_y[cy-1]]
break
else:
cord = [c_x[cx], c_y[cy]]
break
else:
Dis = rgbdis(img[c_y[cy] - parameter[1]][c_x[cx -1] - parameter[0]],
img[c_y[cy - 1] - parameter[1]][c_x[cx] - parameter[0]])
if Dis > 0:
cord = [c_x[cx], c_y[cy-1]]
break
else:
cord = [c_x[cx], c_y[cy]]
break
else:
continue
else:
continue
# cord = find_diff(value)
if num == 260:
break
else:
click_operation(cord)
num += 1