Skip to content

Commit

Permalink
干员选择列表先用PaddleOCR尝试识别
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Sep 30, 2023
1 parent 2a9cdf3 commit c14c5fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
15 changes: 2 additions & 13 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,8 +41,6 @@

from arknights_mower.utils.email import task_template, maa_template, recruit_template

ocr = None


class ArrangeOrder(Enum):
STATUS = 1
Expand Down Expand Up @@ -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]]
Expand All @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions arknights_mower/utils/character_recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions arknights_mower/utils/paddleocr.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit c14c5fe

Please sign in to comment.