Skip to content

Commit

Permalink
试图修复令的识别
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Oct 13, 2023
1 parent 77372e2 commit 953403d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ def double_read_time(self, cord, upperLimit=None, use_digit_reader=False):
def read_screen(self, img, type="mood", limit=24, cord=None):
if cord is not None:
img = img[cord[1]:cord[3], cord[0]:cord[2]]
if 'name' in type:
binary = cv2.threshold(img, 1, 255, cv2.THRESH_BINARY)[1]
x, y, w, h = cv2.boundingRect(binary)
img = img[x:x + w, y:y + h]
try:
ret = rapidocr.engine(img, use_det=False, use_cls=False, use_rec=True)[0]
logger.debug(ret)
Expand Down Expand Up @@ -963,7 +967,7 @@ def read_time(self, cord, upperlimit, error_count=0, use_digit_reader=False):
if use_digit_reader:
time_str = self.digit_reader.get_time(self.recog.gray)
else:
time_str = self.read_screen(self.recog.img, type='time', cord=cord)
time_str = self.read_screen(self.recog.gray, type='time', cord=cord)
try:
h, m, s = str(time_str).split(':')
if int(m) > 60 or int(s) > 60:
Expand Down Expand Up @@ -1837,7 +1841,7 @@ def get_agent_from_room(self, room, read_time_index=None):
if room == 'meeting':
time.sleep(3)
self.recog.update()
clue_res = self.read_screen(self.recog.img, limit=10, cord=(645, 977, 755, 1018))
clue_res = self.read_screen(self.recog.gray, limit=10, cord=(645, 977, 755, 1018))
if clue_res != 11:
self.clue_count = clue_res
logger.info(f'当前拥有线索数量为{self.clue_count}')
Expand Down Expand Up @@ -1865,7 +1869,7 @@ def get_agent_from_room(self, room, read_time_index=None):
interval=1, rebuild=True)
swiped = True
data = {}
_name = self.read_screen(self.recog.img[name_p[i][0][1]:name_p[i][1][1], name_p[i][0][0]:name_p[i][1][0]],
_name = self.read_screen(self.recog.gray[name_p[i][0][1]:name_p[i][1][1], name_p[i][0][0]:name_p[i][1][0]],
type="name")
error_count = 0
while i >= 3 and _name != '' and (
Expand All @@ -1874,7 +1878,7 @@ def get_agent_from_room(self, room, read_time_index=None):
self.swipe((self.recog.w * 0.8, self.recog.h * 0.5), (0, -self.recog.h * 0.45), duration=500,
interval=1, rebuild=True)
_name = self.read_screen(
self.recog.img[name_p[i][0][1]:name_p[i][1][1], name_p[i][0][0]:name_p[i][1][0]], type="name")
self.recog.gray[name_p[i][0][1]:name_p[i][1][1], name_p[i][0][0]:name_p[i][1][0]], type="name")
error_count += 1
if error_count > 1:
raise Exception("超过出错上限")
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/utils/rapidocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def initialize_ocr():
if not engine:
from rapidocr_onnxruntime import RapidOCR

engine = RapidOCR()
engine = RapidOCR(text_score=0.3)

0 comments on commit 953403d

Please sign in to comment.