Skip to content

Commit

Permalink
支持16:9比例下的多分辨率,识别制造站加速总剩余时间
Browse files Browse the repository at this point in the history
1.由原本仅支持1920×1080分辨率改为支持16:9比例下的多分辨率,但是现在的图像识别方案仍然需要一定的清晰度,测试结果是1600×900分辨率能够稳定运行,1600×900分辨率以下会出现识别错误。
2.识别制造站加速总剩余时间,为切换产物功能做准备
  • Loading branch information
Bidgecfah authored Sep 14, 2023
1 parent bf47407 commit f790097
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions arknights_mower/utils/digit_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from pathlib import Path
import os
from .image import loadimg
from .image import loadimg, saveimg
from .. import __rootdir__


Expand All @@ -22,8 +22,9 @@ def __init__(self, template_dir=None):
loadimg(f'{__rootdir__}/resources/drone_count/{i}.png', True)
)

def get_drone(self, img_grey):
drone_part = img_grey[32:76, 1144:1225]
def get_drone(self, img_grey, h, w):

This comment has been minimized.

Copy link
@Shawnsdaddy

Shawnsdaddy Sep 15, 2023

Contributor

@Bidgecfah 一般修改方程的时候你可以在pycharm ctrl + B 查看是否有其他地方调用这个方程。
如果有调用,你新增 input 会导致调用全部失败,建议修改的时候增加预设值

def get_drone(self, img_grey, h=1080, w=1920):

像这样

This comment has been minimized.

Copy link
@Bidgecfah

Bidgecfah Sep 16, 2023

Author Contributor

学到了 合理合理

drone_part = img_grey[h * 32 // 1080:h * 76 // 1080, w * 1144 // 1920:w * 1225 // 1920]
drone_part = cv.resize(drone_part, (81, 44), interpolation=cv.INTER_AREA)
result = {}
for j in range(10):
res = cv.matchTemplate(
Expand All @@ -45,8 +46,9 @@ def get_drone(self, img_grey):
l = [str(result[k]) for k in sorted(result)]
return int("".join(l))

def get_time(self, img_grey):
digit_part = img_grey[510:543, 499:1920]
def get_time(self, img_grey, h, w):
digit_part = img_grey[h * 510 // 1080:h * 543 // 1080, w * 499 // 1920:w]
digit_part = cv.resize(digit_part, (1421, 33), interpolation=cv.INTER_AREA)
result = {}
for j in range(10):
res = cv.matchTemplate(
Expand All @@ -65,10 +67,34 @@ def get_time(self, img_grey):
break
if accept:
if len(result) == 0:
digit_part = digit_part[:, loc[1][i] - 5 : loc[1][i] + 116]
digit_part = digit_part[:, loc[1][i] - 5: loc[1][i] + 116]
offset = loc[1][0] - 5
for m in range(len(loc[1])):
loc[1][m] -= offset
result[loc[1][i]] = j
l = [str(result[k]) for k in sorted(result)]
return f"{l[0]}{l[1]}:{l[2]}{l[3]}:{l[4]}{l[5]}"

def 识别制造加速总剩余时间(self, img_grey, h, w):
时间部分 = img_grey[h * 665 // 1080:h * 709 // 1080, w * 750 // 1920:w * 960 // 1920]
时间部分 = cv.resize(时间部分, (210*58//71, 44*58//71), interpolation=cv.INTER_AREA)
result = {}
for j in range(10):
res = cv.matchTemplate(
时间部分,
self.drone_template[j],
cv.TM_CCORR_NORMED,
)
threshold = 0.92
loc = np.where(res >= threshold)
for i in range(len(loc[0])):
offset = loc[1][i]
accept = True
for o in result:
if abs(o - offset) < 5:
accept = False
break
if accept:
result[loc[1][i]] = j
l = [str(result[k]) for k in sorted(result)]
return f"{l[0]}{l[1]}{l[2]}:{l[3]}{l[4]}:{l[5]}{l[6]}"

0 comments on commit f790097

Please sign in to comment.