Skip to content

Commit

Permalink
Merge branch 'dev_shawn' of https://github.com/Fuynkio/arknights-mower
Browse files Browse the repository at this point in the history
…into dev_shawn
  • Loading branch information
fuyn101 committed Oct 1, 2023
2 parents 98f3155 + a1cb7fb commit 580f521
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 36 deletions.
2 changes: 2 additions & 0 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from arknights_mower.utils.simulator import restart_simulator
from arknights_mower.utils.email import task_template
from arknights_mower.utils.plan import Plan, PlanConfig, Room
import arknights_mower.utils.paddleocr

conf = {}
plan = {}
Expand Down Expand Up @@ -41,6 +42,7 @@ def main(c, p, o={}, child_conn=None):
Pipe.conn = child_conn
logger.info('开始运行Mower')
logger.debug(agent_base_config)
arknights_mower.utils.paddleocr.initialize_ocr()
simulate()

#newbing说用这个来定义休息时间省事
Expand Down
4 changes: 3 additions & 1 deletion arknights_mower/data/ocr.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@
"青积": "青枳",
"苍替": "苍苔",
"刻力": "刻刀",
"泰拉大陆调查": "泰拉大陆调查团"
"泰拉大陆调查": "泰拉大陆调查团",
"子": "",
"森": "森蚺"
}
20 changes: 10 additions & 10 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,16 +1953,16 @@ def agent_arrange(self, plan: tp.BasePlan, get_time=False):
for current_idx, _name in enumerate(plan[room]):
if _name == 'Current':
plan[room][current_idx] = self.op_data.get_current_room(room, True)[current_idx]
if room in self.op_data.run_order_rooms and len(
new_plan) == 0 and self.task.type != TaskTypes.RUN_ORDER:
if plan[room] != self.op_data.get_current_room(room):
logger.debug("检测到插拔房间人员变动!")
run_order_task = find_next_task(self.tasks, datetime.now() + timedelta(minutes=5),
task_type=TaskTypes.RUN_ORDER,
meta_data=room, compare_type=">")
if run_order_task is not None:
logger.info("移除超过5分钟的跑单任务以刷新时间")
self.tasks.remove(run_order_task)
if room in self.op_data.run_order_rooms and len(
new_plan) == 0 and self.task.type != TaskTypes.RUN_ORDER:
if plan[room] != self.op_data.get_current_room(room):
logger.debug("检测到插拔房间人员变动!")
run_order_task = find_next_task(self.tasks, datetime.now() + timedelta(minutes=5),
task_type=TaskTypes.RUN_ORDER,
meta_data=room, compare_type=">")
if run_order_task is not None:
logger.info("移除超过5分钟的跑单任务以刷新时间")
self.tasks.remove(run_order_task)
checked = True
current_room = self.op_data.get_current_room(room, True)
same = len(plan[room]) == len(current_room)
Expand Down
50 changes: 38 additions & 12 deletions arknights_mower/utils/character_recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,36 @@ def sift_recog(query, resolution, draw=False,bigfont = False):
return best


def paddle_recog(__img):
if len(res := arknights_mower.utils.paddleocr.ocr(__img)[1]) > 0:
logger.debug(res)
for r in res:
if r[0] in agent_list:
op_name = r[0]
return op_name
if r[0] in ocr_error:
op_name = ocr_error[r[0]]
logger.debug(f"{r[0]} =====> {op_name}")
return op_name
recog_text = res[0][0]
best = None
best_score = 0
# “森蚺”可能识别成“森”,“孑”可能识别成“子”(子月)
# 以单字猜测双字干员不可靠
# 以“白面鹃”或“白面”匹配“白面鸮”没问题
for x in agent_sorted:
score = -abs(len(x) - len(recog_text))
for c in set(x):
score += 2 if c in recog_text else 0
if score > best_score:
best = x
best_score = score
if best_score > len(best):
logger.debug(f"{recog_text} --?--> {best}")
return best
return None


def agent(img, draw=False):
"""
识别干员总览界面的干员名称
Expand Down Expand Up @@ -172,12 +202,10 @@ def agent(img, draw=False):
ret_agent.append(x[1])
ret_succ.append(poly)
continue
if len(res := arknights_mower.utils.paddleocr.ocr(__img)[1]) > 0:
logger.debug(f"PaddleOCR识别结果:{res}")
if op_name := next((r[0] for r in res if r[0] in agent_list), None):
ret_agent.append(op_name)
ret_succ.append(poly)
continue
if op_name := paddle_recog(__img):
ret_agent.append(op_name)
ret_succ.append(poly)
continue
res = sift_recog(__img, resolution, draw)
if (res is not None) and res in agent_list:
ret_agent.append(res)
Expand All @@ -191,12 +219,10 @@ def agent(img, draw=False):
else:
if 80 <= np.min(__img):
continue
if len(res := arknights_mower.utils.paddleocr.ocr(__img)[1]) > 0:
logger.debug(f"PaddleOCR识别结果:{res}")
if op_name := next((r[0] for r in res if r[0] in agent_list), None):
ret_agent.append(op_name)
ret_succ.append(poly)
continue
if op_name := paddle_recog(__img):
ret_agent.append(op_name)
ret_succ.append(poly)
continue
res = sift_recog(__img, resolution, draw)
if res is not None:
ret_agent.append(res)
Expand Down
33 changes: 20 additions & 13 deletions arknights_mower/utils/paddleocr.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import os
from paddleocr import PaddleOCR


det_model_dir = os.path.join(os.getcwd(), "tmp", "paddle", "det", "ch")
rec_model_dir = os.path.join(os.getcwd(), "tmp", "paddle", "rec", "ch")
cls_model_dir = os.path.join(os.getcwd(), "tmp", "paddle", "cls")
ocr = None

ocr = PaddleOCR(
enable_mkldnn=False,
use_angle_cls=False,
cls=False,
show_log=False,
det_model_dir=det_model_dir,
rec_model_dir=rec_model_dir,
cls_model_dir=cls_model_dir,
)

def initialize_ocr():
det_model_dir = os.path.join(os.getcwd(), "tmp", "paddle", "det", "ch")
rec_model_dir = os.path.join(os.getcwd(), "tmp", "paddle", "rec", "ch")
cls_model_dir = os.path.join(os.getcwd(), "tmp", "paddle", "cls")

global ocr
if not ocr:
from paddleocr import PaddleOCR

ocr = PaddleOCR(
enable_mkldnn=False,
use_angle_cls=False,
cls=False,
show_log=False,
det_model_dir=det_model_dir,
rec_model_dir=rec_model_dir,
cls_model_dir=cls_model_dir,
)
2 changes: 2 additions & 0 deletions diy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from arknights_mower.utils.logic_expression import LogicExpression
from arknights_mower.utils.simulator import restart_simulator
from arknights_mower.utils.plan import Plan, PlanConfig, Room
import arknights_mower.utils.paddleocr

# 下面不能删除
from arknights_mower.utils.operators import Operators, Operator, Dormitory
Expand Down Expand Up @@ -401,4 +402,5 @@ def simulate():
# debuglog()
atexit.register(save_state)
savelog()
arknights_mower.utils.paddleocr.initialize_ocr()
simulate()

0 comments on commit 580f521

Please sign in to comment.