feat.OcrReplace支持正则替换,优化公招识别

This commit is contained in:
MistEO
2021-12-15 00:18:29 +08:00
parent 0d082d1635
commit ad68e046f1
4 changed files with 18 additions and 10 deletions

View File

@@ -1089,7 +1089,12 @@
480,
120
],
"ocrReplace": []
"ocrReplace": [
[
".+击干员",
"狙击干员"
]
]
},
"RecruitRefresh": {
"action": "clickSelf",

View File

@@ -1,6 +1,7 @@
#include "OcrImageAnalyzer.h"
#include "AsstUtils.hpp"
#include <regex>
#include "Logger.hpp"
#include "Resource.h"
@@ -12,8 +13,8 @@ bool asst::OcrImageAnalyzer::analyze()
if (!m_replace.empty()) {
TextRectProc text_replace = [&](TextRect& tr) -> bool {
for (const auto& [old_str, new_str] : m_replace) {
tr.text = utils::string_replace_all(tr.text, old_str, new_str);
for (const auto& [regex, new_str] : m_replace) {
tr.text = std::regex_replace(tr.text, std::regex(regex), new_str);
}
return true;
};

View File

@@ -1,5 +1,7 @@
#include "ProcessTaskImageAnalyzer.h"
#include <regex>
#include "AsstUtils.hpp"
#include "Logger.hpp"
#include "MatchImageAnalyzer.h"
@@ -39,8 +41,8 @@ bool asst::ProcessTaskImageAnalyzer::ocr_analyze(std::shared_ptr<TaskInfo> task_
// 先尝试从缓存的结果里找
for (const TextRect& tr : m_ocr_cache) {
TextRect temp = tr;
for (const auto& [old_str, new_str] : ocr_task_ptr->replace_map) {
temp.text = utils::string_replace_all(temp.text, old_str, new_str);
for (const auto& [regex, new_str] : ocr_task_ptr->replace_map) {
temp.text = std::regex_replace(temp.text, std::regex(regex), new_str);
}
for (const auto& text : ocr_task_ptr->text) {
bool flag = false;

View File

@@ -9,10 +9,10 @@ bool asst::RecruitImageAnalyzer::analyze()
m_tags_result.clear();
m_set_time_rect.clear();
bool ret = time_analyze();
ret |= tags_analyze();
ret |= confirm_analyze();
ret |= refresh_analyze();
time_analyze();
refresh_analyze();
bool ret = tags_analyze();
ret &= confirm_analyze();
return ret;
}