diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index c977aba9c..ad17de8a0 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -29,7 +29,7 @@ from ..utils.solver import BaseSolver from ..utils.datetime import get_server_weekday, the_same_time from arknights_mower.utils.news import get_update_time -from paddleocr import PaddleOCR +import arknights_mower.utils.paddleocr import cv2 from ctypes import CFUNCTYPE, c_int, c_char_p, c_void_p @@ -41,8 +41,6 @@ from arknights_mower.utils.email import task_template, maa_template, recruit_template -ocr = None - class ArrangeOrder(Enum): STATUS = 1 @@ -900,14 +898,6 @@ def double_read_time(self, cord, upperLimit=None, use_digit_reader=False): execute_time = datetime.now() + timedelta(seconds=(time_in_seconds)) return execute_time - def initialize_paddle(self): - 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 ocr is 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 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]] @@ -916,8 +906,7 @@ def read_screen(self, img, type="mood", limit=24, cord=None): for x in range(0, 4): img = cv2.vconcat([img, img]) try: - self.initialize_paddle() - rets = ocr.ocr(img, cls=False) + rets = arknights_mower.utils.paddleocr.ocr.ocr(img, cls=False) line_conf = [] for idx in range(len(rets[0])): res = rets[0][idx] diff --git a/arknights_mower/utils/character_recognize.py b/arknights_mower/utils/character_recognize.py index a4dff96b9..a7c060ca9 100644 --- a/arknights_mower/utils/character_recognize.py +++ b/arknights_mower/utils/character_recognize.py @@ -16,6 +16,8 @@ from .recognize import RecognizeError from ..ocr import ocrhandle +import arknights_mower.utils.paddleocr + def poly_center(poly): return (np.average([x[0] for x in poly]), np.average([x[1] for x in poly])) @@ -170,6 +172,11 @@ 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[0]}") + ret_agent.append(res[0][0]) + 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) @@ -183,6 +190,11 @@ 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[0]}") + ret_agent.append(res[0][0]) + ret_succ.append(poly) + continue res = sift_recog(__img, resolution, draw) if res is not None: ret_agent.append(res) diff --git a/arknights_mower/utils/paddleocr.py b/arknights_mower/utils/paddleocr.py new file mode 100644 index 000000000..ad26d608a --- /dev/null +++ b/arknights_mower/utils/paddleocr.py @@ -0,0 +1,17 @@ +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 = 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, +)