Skip to content

Commit

Permalink
v5.5 优化+改图
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYX committed Sep 14, 2023
1 parent dd7113f commit 1226598
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 10 deletions.
Binary file added imgs/fate_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imgs/maps/22212/target.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imgs/maps/96641/target.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/maps/96642/init.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/maps/96642/map_4042_4026_.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/maps/96642/target.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 20 additions & 6 deletions states.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def route(self):
self.in_battle = 0
self.init_map()
fail_cnt = 0
fail_time = time.time()
fail_time = 0
self.confirm_time = 0
self._stop = os.stat("imgs/mon" + self.tss).st_size != 141882
while True:
if self._stop:
Expand Down Expand Up @@ -177,14 +178,19 @@ def route(self):
res = self.normal()
# 未匹配到图片,降低匹配阈值,若一直无法匹配则乱点
if res == 0:
self.click_text(['空白处','确认','点击'])
if time.time()-self.confirm_time>4:
if self.click_text(['空白处','确认','点击']):
time.sleep(0.5)
if self.ts.nothing:
self.in_battle = time.time()
print('nothing')
if time.time()-self.in_battle>7:
if self.threshold == 0.97 and fail_cnt==0:
log.info("匹配不到任何图标")
fail_time = time.time()
if self.threshold > 0.94:
self.threshold -= 0.009
elif time.time()-fail_time>2.5:
if self.threshold > 0.95:
self.threshold -= 0.015
elif time.time()-fail_time>4.5:
time.sleep(0.15)
if fail_cnt <= 1:
self.click((0.5000, 0.1454))
Expand Down Expand Up @@ -297,6 +303,7 @@ def normal(self):
self.click(self.calc_point((0.5042, 0.3204), res_down[0]))
self.click((0.1203, 0.1093))
time.sleep(0.35)
self.confirm_time = time.time()
return 1
# F交互界面
elif self.check("f", 0.4443, 0.4417, mask="mask_f1"):
Expand Down Expand Up @@ -539,8 +546,11 @@ def normal(self):
)
time.sleep(0.3)
self.click((0.1635, 0.1056))
elif self.check("fate_2", 0.1797, 0.1009):
self.click((0.1797, 0.1009))
self.confirm_time = time.time()
elif self.check("fate", 0.9458, 0.9481):
time.sleep(1)
time.sleep(0.6)
self.get_screen()
img = self.check("z", 0.4969, 0.3750, mask="mask_fate", large=False)
res = self.ts.split_and_find([self.fate], img)
Expand Down Expand Up @@ -602,14 +612,17 @@ def normal(self):
res = self.ts.split_and_find(self.tk.strange, img, mode="strange")
self.click(self.calc_point((0.5000, 0.7333), res[0]))
self.click((0.1365, 0.1093))
self.confirm_time = time.time()
# 丢弃奇物
elif self.check("drop", 0.9406, 0.9491):
self.click((0.4714, 0.5500))
self.click((0.1339, 0.1028))
self.confirm_time = time.time()
elif self.check("drop_bless", 0.9417, 0.9481, threshold=0.95):
self.click((0.4714, 0.5500))
time.sleep(0.5)
self.click((0.1203, 0.1093))
self.confirm_time = time.time()
elif self.check("setting", 0.9734, 0.3009, threshold=0.98):
self.click((0.9734, 0.3009))
time.sleep(2)
Expand Down Expand Up @@ -640,6 +653,7 @@ def normal(self):
time.sleep(0.3)
self.get_screen()
self.press("esc")
self.confirm_time = time.time()
return 0

def find_latest_modified_file(self, folder_path):
Expand Down
6 changes: 5 additions & 1 deletion utils/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def sim(self,text,img=None):
log.info('error_sim|'+text+'|'+self.text+'|')
f[i+1][0]=max(f[i][0],f[i+1][0])
f[i+1][1]=max(f[i][1],f[i+1][1],f[i][0]+1)
if text.strip() in ['胜军']:
if text.strip() in ['胜军','空白处','确认','点击']:
return f[-1][0]>=len(text)-2
else:
return f[-1][1]>=len(text)-2
Expand Down Expand Up @@ -108,8 +108,12 @@ def split_and_find(self,key_list,img,mode=None,bless_skip=1):
return (rcx-img.shape[1]//2,rcy-img.shape[0]//2),find

def find_text(self, img, text):
self.nothing = 1
for res in self.ts.detect_and_ocr(img):
self.text = res.ocr_text
if len(self.text.strip())>1 and 'UID' not in self.text:
self.nothing = 0
print(self.text)
for txt in text:
if self.sim(txt):
print("识别到文本:",txt)
Expand Down
6 changes: 3 additions & 3 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def click_text(self, text):
1 - (pt[0][1] + pt[2][1]) / 2 / self.yy,
)
)
return 1

# 由click_target调用,返回图片匹配结果
def scan_screenshot(self, prepared):
Expand Down Expand Up @@ -309,8 +310,7 @@ def check(self, path, x, y, mask=None, threshold=None, large=True):
self.ty = y - (max_loc[1] - 0.5 * local_screen.shape[0]) / self.yy
self.tm = max_val
if max_val > threshold:
if self.last_info != path:
log.info("匹配到图片 %s 相似度 %f 阈值 %f" % (path, max_val, threshold))
log.info("匹配到图片 %s 相似度 %f 阈值 %f" % (path, max_val, threshold))
self.last_info = path
return max_val > threshold

Expand Down Expand Up @@ -1079,7 +1079,7 @@ def match_scr(self, img):
except:
pass
res = sorted(res, key=lambda x: x[0])[-4:]
if res[-1][0]>res[-2][0]+0.09 and res[-1][0]>0.4:
if res[-1][0]>res[-2][0]+0.075 and res[-1][0]>0.4:
return res[-1][1], 0.9
i_s = [x[1] for x in res]
for i in i_s[::-1]:
Expand Down

0 comments on commit 1226598

Please sign in to comment.