-
Notifications
You must be signed in to change notification settings - Fork 2
/
ilx.py
279 lines (186 loc) · 8.81 KB
/
ilx.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import cv2,testAuth
from PIL import ImageGrab,ImageOps
from pynput.mouse import Button,Controller
import time,cv2,os,sys
import numpy as np
from PyQt5.QtCore import QRunnable
#problems:
# this file is initialzed every time new instance is ran, need to make it so instance is kept open and use run() every time it is running instead of killing it
# similarity still not great, can make better by distorting lower res images
# dimensions can probably use work, the numbers look weird
# im very lazy
class Runnables(QRunnable):
def __init__(self,program,res,agent):
super().__init__()
self.p=program
self.resW=0
self.resH=0
self.button=Button.left
self.running=True
self.enabled=False
self.resolution=res
self.agents=program.agents
ind=self.agents.index(agent)
self.img1= agentPool[ind]
self.img1Mask=cv2.bitwise_and(self.img1, self.img1, mask=self.p.getMask(self.img1))
self.currentAgent=agent
self.getDimension()
def changeImg(self):
ind=self.agents.index(self.currentAgent)
self.img1= agentPool[ind]
# self.p.show_agent(testAuth.pil2pixmap(testAuth.cv2toPIL(self.img1).resize((60,60))) )
self.p.masker=self.p.getMask(self.img1)
self.p.show_agent(self.currentAgent)
self.img1Mask=cv2.bitwise_and(self.img1, self.img1, mask=self.p.getMask(self.img1))
def run(self):
self.counter=0
while self.running:
if self.enabled:
if(self.p.checkBoxRes.isChecked()):
self.getDimension2()
image = ImageGrab.grab()
imagedupe=image
best=0
points=[0,0]
for p in self.points:
newX=p[0]
newY=p[1]
border=(newX,newY,self.screen_width-(newX+self.add),self.screen_height-(newY+self.add))
try:
image=ImageOps.crop(image,border)
image=image.resize(size=(80,80))
img2 = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)
similarity = self.similar(self.img1, img2)
except Exception as e:
similarity=0
# pass
image=imagedupe
if(similarity>0.5 and similarity>best):
best=similarity
points=p
if best>0:
for _ in range(3):
press=(points[0]*2+self.add)/2,(points[1]*2+self.add)/2
mouses.position=press
time.sleep(0.02)
self.mousepress(2)
mouses.position=self.returnpoint
time.sleep(0.01)
self.mousepress(2)
self.p.changeRunning()
time.sleep(.01)
#x2
def mousepress(self,times):
for i in range(times):
mouses.press(self.button)
mouses.release(self.button)
def similar(self,img1, img2):
orb = cv2.ORB_create()
im2 = cv2.bitwise_and(img2, img2, mask=self.p.masker)
dd,i1 = orb.detectAndCompute(self.img1Mask, None)
vv,i2 = orb.detectAndCompute(im2, None)
bfm = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bfm.match(i1, i2)
sim = [i for i in matches if i.distance < 55]
# print(len(sim) / len(matches))
self.p.i+=1
if len(matches) == 0:
return 0
return len(sim) / len(matches)
# def similar2(self,img1,img2):
# t0=time.time()
# img1=cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
# img2=cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
# i1 = cv2.bitwise_and(img1, img1, mask=self.p.masker)
# i2 = cv2.bitwise_and(img2, img2, mask=self.p.masker)
# sim, diff = structural_similarity(i1, i2, full=True)
# # print(sim)
# # cv2.imwrite("current.png",i1)
# # cv2.imwrite(self.agents[(self.p.i) % (len(self.agents))]+".png",i2)
# self.p.i+=1
# return sim>=.7
def getDimension(self):
try:
res=self.resolution
ind=res.index('x')
v=res[:ind]
x=res[ind+1:]
self.screen_width=int(v)
self.screen_height=int(x)
res=round((int(v)/int(x)),2)
except: #default
self.screen_width=1920
self.screen_height=1080
res=round(1920/1080,2)
#scaling of agent select screen, could be more precise i think
self.diff=(7/90)*self.screen_height #gap between points
self.returnpoint=(int(self.screen_width/2), int(self.screen_height*.75)) #confirm agent
self.startpoint=((self.screen_width-(self.screen_height*.85))/2),0.8194*self.screen_height #first agent
self.add=(6/81)*self.screen_height #size of agent (square so x and y are the same)
self.points=[]
num=11#number of iterations on the row
rows=2
for i in range(rows):
Xpoint=self.startpoint[0]
Ypoint=self.startpoint[1]
Ypoint+=(self.diff*i)
# if i==0:
# num=10
# else:
# num=9
for x in range(num):
self.points.append((Xpoint,Ypoint))
Xpoint+=(self.diff)
# print(self.points)
def getDimension2(self): #gets width and height and runs first function
res=ImageGrab.grab()
res=res.size
if self.resW==res[0] and self.resH==res[1]:
pass
else:
self.resW=res[0]
self.resH=res[1]
r=str(self.resW)+"x"+str(self.resH)
self.resolution=r
self.getDimension()
self.p.comboBox.setCurrentText(r)
t='Current Resolution: '+r
self.p.label_2.setText(t)
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
icon=resource_path('./images/myIcon.ico')
# Make cache and lazily load in images
Astra= cv2.imread(resource_path('./images/Astra.png'), cv2.IMREAD_UNCHANGED)
Brimstone= cv2.imread(resource_path('./images/Brimstone.png'), cv2.IMREAD_UNCHANGED)
Breach= cv2.imread(resource_path('./images/Breach.png'), cv2.IMREAD_UNCHANGED)
Cypher= cv2.imread(resource_path('./images/Cypher.png'), cv2.IMREAD_UNCHANGED)
Chamber= cv2.imread(resource_path('./images/Chamber.png'), cv2.IMREAD_UNCHANGED)
Jett= cv2.imread(resource_path('./images/Jett.png'), cv2.IMREAD_UNCHANGED)
KayO= cv2.imread(resource_path('./images/KayO.png'), cv2.IMREAD_UNCHANGED)
Killjoy= cv2.imread(resource_path('./images/Killjoy.png'), cv2.IMREAD_UNCHANGED)
Neon= cv2.imread(resource_path('./images/Neon.png'), cv2.IMREAD_UNCHANGED)
Omen= cv2.imread(resource_path('./images/Omen.png'), cv2.IMREAD_UNCHANGED)
Phoenix= cv2.imread(resource_path('./images/Phoenix.png'), cv2.IMREAD_UNCHANGED)
Raze= cv2.imread(resource_path('./images/Raze.png'), cv2.IMREAD_UNCHANGED)
Reyna= cv2.imread(resource_path('./images/Reyna.png'), cv2.IMREAD_UNCHANGED)
Sage= cv2.imread(resource_path('./images/Sage.png'), cv2.IMREAD_UNCHANGED)
Skye= cv2.imread(resource_path('./images/Skye.png'), cv2.IMREAD_UNCHANGED)
Sova= cv2.imread(resource_path('./images/Sova.png'), cv2.IMREAD_UNCHANGED)
Viper= cv2.imread(resource_path('./images/Viper.png'), cv2.IMREAD_UNCHANGED)
Yoru= cv2.imread(resource_path('./images/Yoru.png'), cv2.IMREAD_UNCHANGED)
Fade= cv2.imread(resource_path('./images/Fade.png'), cv2.IMREAD_UNCHANGED)
Harbor= cv2.imread(resource_path('./images/Harbor.png'), cv2.IMREAD_UNCHANGED)
Gekko= cv2.imread(resource_path('./images/Gekko.png'), cv2.IMREAD_UNCHANGED)
agentPool=[Astra,Breach,Brimstone,Chamber,Cypher,Fade,Gekko,Harbor,Jett,KayO,Killjoy,Neon,Omen,Phoenix,Raze,Reyna,Sage,Skye,Sova,Viper,Yoru]
def mousepress(times): #idk why this is here
res=ImageGrab.grab()
res=res.size
x=res[0]
y=res[1]
mouses.position=(x/2,y/2)
for i in range(times):
mouses.press(Button.left)
mouses.release(Button.left)
mouses = Controller()