Skip to content

Commit

Permalink
修正PaddleOCR猜干员,添加单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Oct 5, 2023
1 parent abe8a5e commit 3c52770
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
23 changes: 23 additions & 0 deletions arknights_mower/tests/paddle_guess_agent_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
from arknights_mower.utils.character_recognize import paddle_guess_agent


class TestPaddleGuessAgent(unittest.TestCase):
def test_one_match(self):
self.assertEqual(paddle_guess_agent("子"), None)
self.assertEqual(paddle_guess_agent("森"), None)
self.assertEqual(paddle_guess_agent("叶"), None)

def test_two_match_two(self):
self.assertEqual(paddle_guess_agent("愧影"), "傀影")

def test_two_match_three(self):
self.assertEqual(paddle_guess_agent("白面"), "白面鸮")

def test_three_match_three(self):
self.assertEqual(paddle_guess_agent("白面鹃"), "白面鸮")

def long_match(self):
self.assertEqual(paddle_guess_agent("罗比塔"), "罗比菈塔")
self.assertEqual(paddle_guess_agent("屯艾雅法拉"), "纯烬艾雅法拉")
self.assertEqual(paddle_guess_agent("屯炽艾雅法拉"), "纯烬艾雅法拉")
40 changes: 23 additions & 17 deletions arknights_mower/utils/character_recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ def sift_recog(query, resolution, draw=False,bigfont = False):
return best


def paddle_guess_agent(guess):
best = None
best_score = 0
# “森蚺”可能识别成“森”,“孑”可能识别成“子”(子月)
# 以单字猜测双字干员不可靠
# 以“白面鹃”或“白面”匹配“白面鸮”没问题
# 注意避免“白面”匹配到“白雪”
# “屯艾雅法拉”应匹配“纯烬艾雅法拉”,而非“艾雅法拉”
for x in agent_sorted:
score = -abs(len(x) - len(guess))
for c in set(x):
score += 3 if c in guess else 0
if score >= best_score:
best = x
best_score = score
if best_score > len(best):
logger.debug(f"{guess} --?--> {best}")
return best
else:
return None


def paddle_recog(__img):
if len(res := arknights_mower.utils.paddleocr.ocr(__img)[1]) > 0:
logger.debug(res)
Expand All @@ -137,23 +159,7 @@ def paddle_recog(__img):
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 += 3 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 paddle_guess_agent(recog_text)
return None


Expand Down

0 comments on commit 3c52770

Please sign in to comment.