Skip to content

Commit c0668f1

Browse files
authored
fix: 技能识别时只识别中英文字符和数字 (#220)
1 parent 6b3bd44 commit c0668f1

File tree

6 files changed

+87
-25
lines changed

6 files changed

+87
-25
lines changed

bot/recog/ocr.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import cv2
2+
import re
23
import paddleocr
34
from difflib import SequenceMatcher
45
import bot.base.log as logger
@@ -28,6 +29,10 @@ def ocr_line(img, lang="ch"):
2829
text += text_info[1][0]
2930
return text
3031

32+
# 剔除所有符号, 只保留中文字符, 英文字符, 数字
33+
def extract_chinese_english_digits(text: str) -> str:
34+
return re.sub(r"[^a-zA-Z0-9\u4e00-\u9fff]", "", text)
35+
3136
# ocr_digits 限制只识别数字,可以提升数字识别的准确度
3237
def ocr_digits(img):
3338
res = OCR_EN.ocr(img, cls=False)[0]
@@ -52,10 +57,12 @@ def find_text_pos(ocr_result, target):
5257
return result
5358

5459

55-
def find_similar_text(target_text, ref_text_list, threshold=0):
60+
def find_similar_text(target_text: str, ref_text_list: list[str], threshold=0):
61+
# 去除所有空格, 并把英文字符转为小写
62+
target_text = target_text.replace(" ", "").lower()
5663
result = ""
5764
for ref_text in ref_text_list:
58-
s = SequenceMatcher(None, target_text, ref_text)
65+
s = SequenceMatcher(None, target_text, ref_text.replace(" ", "").lower())
5966
if s.ratio() > threshold:
6067
result = ref_text
6168
threshold = s.ratio()

module/umamusume/script/cultivate_task/parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from bot.base.task import TaskStatus, EndTaskReason
99
from bot.recog.image_matcher import image_match, compare_color_equal
10-
from bot.recog.ocr import ocr_line, find_similar_text
10+
from bot.recog.ocr import ocr_line, find_similar_text, extract_chinese_english_digits
1111
from module.umamusume.asset.race_data import RACE_LIST
1212
from module.umamusume.context import UmamusumeContext
1313
from module.umamusume.types import SupportCardInfo
@@ -367,7 +367,7 @@ def get_skill_list(img, skill: list[str], skill_blacklist: list[str]) -> list:
367367

368368
skill_name_img = skill_info_img[10: 47, 100: 445]
369369
skill_cost_img = skill_info_img[69: 99, 525: 588]
370-
text = ocr_line(skill_name_img)
370+
text = extract_chinese_english_digits(ocr_line(skill_name_img))
371371
cost = re.sub("\\D", "", ocr_line(skill_cost_img))
372372

373373
# 检查是不是金色技能

public/assets/index.5ae02e0c.css renamed to public/assets/index.3757966e.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/index.161d56bd.js renamed to public/assets/index.e7e7ff2c.js

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<meta charset="utf-8">
99
<meta http-equiv="X-UA-Compatible" content="IE=edge">
1010
<meta name="viewport" content="width=device-width,initial-scale=1.0">
11-
<script type="module" crossorigin src="./assets/index.161d56bd.js"></script>
12-
<link rel="stylesheet" href="./assets/index.5ae02e0c.css">
11+
<script type="module" crossorigin src="./assets/index.e7e7ff2c.js"></script>
12+
<link rel="stylesheet" href="./assets/index.3757966e.css">
1313
</head>
1414
<body>
1515
<div id="app"></div>

web/src/components/TaskEditModal.vue

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
<div class="form-group row">
329329
<label class="col-sm-3" for="'skill-learn-' + item.id">❗ 学习优先级 {{ item.priority+1 }}</label>
330330
<div class="col-sm-6">
331-
<textarea type="text" v-model="item.skills" class="form-control" id="skill-learn-priority" placeholder="技能1名称,技能2名称,....(使用英文逗号)"></textarea>
331+
<textarea type="text" v-model="item.skills" class="form-control" id="skill-learn-priority" :placeholder="'技能1名称,技能2名称,....(使用英文逗号)\n技能名称可忽略符号, 空格和特殊字符'" ></textarea>
332332
</div>
333333
<div class="col-sm-3">
334334
<span class="red-button auto-btn ml-2" v-on:click="deleteBox(item,index)">删除当前优先级</span>
@@ -1255,4 +1255,58 @@ export default {
12551255
display: inline-block;
12561256
transition: all 0.3s ease;
12571257
}
1258+
1259+
/* Tooltip 帮助样式 -- 悬浮鼠标后展示提示*/
1260+
.tooltip-help {
1261+
display: inline-block;
1262+
margin-left: 8px;
1263+
position: relative;
1264+
cursor: default;
1265+
line-height: 1; /* 保持与文本对齐,避免图标垂直压缩 */
1266+
vertical-align: middle;
1267+
}
1268+
.tooltip-help-text {
1269+
visibility: hidden;
1270+
/* 使用自适应宽度但限制最大值,避免在窄屏上溢出 */
1271+
width: auto;
1272+
max-width: 720px;
1273+
display: block; /* 确保为块级元素以便 min-width 生效 */
1274+
min-width: 160px;
1275+
white-space: normal; /* 允许换行 */
1276+
word-break: normal;
1277+
overflow-wrap: break-word;
1278+
background-color: rgba(0,0,0,0.85);
1279+
color: #fff;
1280+
text-align: left;
1281+
border-radius: 4px;
1282+
padding: 8px;
1283+
position: absolute;
1284+
z-index: 2000;
1285+
bottom: 140%;
1286+
left: 50%;
1287+
transform: translateX(-50%);
1288+
font-size: 0.9rem;
1289+
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
1290+
box-sizing: border-box;
1291+
line-height: 1.3; /* 改善可读性,避免文字重叠 */
1292+
/* 强制横向排版,覆盖可能的全局竖排规则 */
1293+
writing-mode: horizontal-tb !important;
1294+
text-orientation: mixed !important;
1295+
direction: ltr !important;
1296+
min-height: 1.2em;
1297+
}
1298+
.tooltip-help-text::after {
1299+
content: "";
1300+
position: absolute;
1301+
top: 100%;
1302+
left: 50%;
1303+
transform: translateX(-50%);
1304+
border-width: 6px;
1305+
border-style: solid;
1306+
border-color: rgba(0,0,0,0.85) transparent transparent transparent;
1307+
}
1308+
.tooltip-help:hover .tooltip-help-text,
1309+
.tooltip-help:focus .tooltip-help-text {
1310+
visibility: visible;
1311+
}
12581312
</style>

0 commit comments

Comments
 (0)