fix: 外服训练室技能名可能被部分替换成干员名

This commit is contained in:
uye
2025-07-11 01:28:28 +08:00
parent c3c69c7e1f
commit ce96cef6ec

View File

@@ -56,29 +56,50 @@ std::optional<asst::InfrastTrainingTask::TrainingStatus> asst::InfrastTrainingTa
return TrainingStatus::Idle;
}
const auto& replace_map = Task.get<OcrTaskInfo>("CharsNameOcrReplace")->replace_map;
std::vector<std::pair<std::string, std::string>> task_replace =
Task.get<OcrTaskInfo>("InfrastTrainingOperatorAndSkill")->replace_map;
ranges::copy(replace_map, std::back_inserter(task_replace));
RegionOCRer rec_analyzer(image);
rec_analyzer.set_task_info("InfrastTrainingOperatorAndSkill");
rec_analyzer.set_replace(task_replace);
rec_analyzer.set_use_raw(true);
if (!rec_analyzer.analyze()) {
Log.error(__FUNCTION__, "recognition failed");
return std::nullopt;
{
const auto& replace_map = Task.get<OcrTaskInfo>("CharsNameOcrReplace")->replace_map;
std::vector<std::pair<std::string, std::string>> task_replace =
Task.get<OcrTaskInfo>("InfrastTrainingOperatorAndSkill")->replace_map;
ranges::copy(replace_map, std::back_inserter(task_replace));
RegionOCRer name_analyzer(image);
name_analyzer.set_task_info("InfrastTrainingOperatorAndSkill");
name_analyzer.set_replace(task_replace);
name_analyzer.set_use_raw(true);
if (!name_analyzer.analyze()) {
Log.error(__FUNCTION__, "operator name recognition failed");
return std::nullopt;
}
std::string name_str = name_analyzer.get_result().text;
size_t separation_pos = name_str.find('\n');
if (separation_pos == std::string::npos) {
Log.error(__FUNCTION__, "separate string failed");
return std::nullopt;
}
// '\n'前为干员名,'\n'后为技能名
m_operator_name = name_str.substr(0, separation_pos);
}
std::string raw_str = rec_analyzer.get_result().text;
size_t separation_pos = raw_str.find('\n');
if (separation_pos == std::string::npos) {
Log.error(__FUNCTION__, "separate string failed");
return std::nullopt;
{
RegionOCRer skill_analyzer(image);
skill_analyzer.set_task_info("InfrastTrainingOperatorAndSkill");
skill_analyzer.set_use_raw(true);
if (!skill_analyzer.analyze()) {
Log.error(__FUNCTION__, "skill name recognition failed");
return std::nullopt;
}
std::string skill_str = skill_analyzer.get_result().text;
size_t separation_pos = skill_str.find('\n');
if (separation_pos == std::string::npos) {
Log.error(__FUNCTION__, "separate string failed");
return std::nullopt;
}
m_skill_name = skill_str.substr(separation_pos + 1);
}
// '\n'前为干员名,'\n'后为技能名
m_operator_name = raw_str.substr(0, separation_pos);
m_skill_name = raw_str.substr(separation_pos + 1, raw_str.length() - separation_pos + 1);
Rect roi = Task.get("InfrastTrainingSkillImg")->roi;
m_skill_img = image(make_rect<cv::Rect>(roi));