diff --git a/arknights_mower/__main__.py b/arknights_mower/__main__.py index 5261eedfe..e7d3ffc01 100644 --- a/arknights_mower/__main__.py +++ b/arknights_mower/__main__.py @@ -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 = {} @@ -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说用这个来定义休息时间省事 diff --git a/arknights_mower/utils/paddleocr.py b/arknights_mower/utils/paddleocr.py index ad26d608a..09323bc92 100644 --- a/arknights_mower/utils/paddleocr.py +++ b/arknights_mower/utils/paddleocr.py @@ -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, + )