mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
支持替换OCR常见的识别错误、增加点击9小时的功能
This commit is contained in:
@@ -36,6 +36,7 @@ namespace asst {
|
||||
Options m_options;
|
||||
std::unordered_map<std::string, TaskInfo> m_tasks;
|
||||
std::unordered_map<std::string, EmulatorInfo> m_handles;
|
||||
std::unordered_map<std::string, std::string> m_ocr_replace;
|
||||
|
||||
private:
|
||||
bool _load(const std::string& filename);
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace asst {
|
||||
std::optional<Rect> find_text(const cv::Mat& mat, const std::string& text);
|
||||
std::vector<TextArea> find_text(const cv::Mat& mat, const std::vector<std::string>& texts);
|
||||
std::vector<TextArea> find_text(const cv::Mat& mat, const std::unordered_set<std::string>& texts);
|
||||
|
||||
|
||||
std::vector<TextArea> ocr_detect(const cv::Mat& mat);
|
||||
private:
|
||||
cv::Mat image_2_hist(const cv::Mat& src);
|
||||
double image_hist_comp(const cv::Mat& src, const cv::MatND& hist);
|
||||
static asst::Rect cvrect_2_rect(const cv::Rect& cvRect) {
|
||||
return asst::Rect(cvRect.x, cvRect.y, cvRect.width, cvRect.height);
|
||||
}
|
||||
std::vector<TextArea> ocr_detect(const cv::Mat& mat);
|
||||
|
||||
// return pair< suitability, raw opencv::point>
|
||||
std::pair<double, cv::Point> match_template(const cv::Mat& cur, const cv::Mat& templ);
|
||||
|
||||
@@ -202,14 +202,41 @@ void asst::Assistance::find_and_clac_tags(bool need_click)
|
||||
{
|
||||
DebugTraceFunction;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
const cv::Mat& image = get_format_image();
|
||||
set_control_scale(image.cols, image.rows);
|
||||
|
||||
const std::vector<TextArea>& ider_result = m_pIder->find_text(image, m_recruit_configer.m_all_tags);
|
||||
lock.unlock();
|
||||
|
||||
if (need_click) {
|
||||
start("RecruitTime");
|
||||
}
|
||||
|
||||
std::vector<TextArea> ider_result = m_pIder->ocr_detect(image);
|
||||
std::vector<TextArea> filt_result;
|
||||
std::string ider_str;
|
||||
for (TextArea& res : ider_result) {
|
||||
// 替换一些常见的文字识别错误
|
||||
// TODO: 这块时间复杂度有点高,待优化
|
||||
for (const auto& [src, cor] : m_configer.m_ocr_replace) {
|
||||
res.text = StringReplaceAll(res.text, src, cor);
|
||||
}
|
||||
ider_str += res.text + " ,";
|
||||
for (const std::string& t : m_recruit_configer.m_all_tags) {
|
||||
if (res.text == t) {
|
||||
filt_result.emplace_back(std::move(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ider_str.back() == ',') {
|
||||
ider_str.pop_back();
|
||||
}
|
||||
DebugTrace("All ocr text: ", Utf8ToGbk(ider_str));
|
||||
|
||||
std::vector<std::string> tags;
|
||||
std::string tags_str;
|
||||
for (const TextArea& t_a : ider_result) {
|
||||
for (const TextArea& t_a : filt_result) {
|
||||
tags.emplace_back(t_a.text);
|
||||
tags_str += t_a.text + " ,";
|
||||
}
|
||||
@@ -321,13 +348,16 @@ void asst::Assistance::find_and_clac_tags(bool need_click)
|
||||
if (need_click && !result_vector.empty()) {
|
||||
const std::vector<std::string>& final_tags = result_vector[0].first;
|
||||
std::vector<TextArea> final_text_areas;
|
||||
for (const TextArea& text_area : ider_result) {
|
||||
|
||||
lock.lock();
|
||||
for (const TextArea& text_area : filt_result) {
|
||||
if (std::find(final_tags.cbegin(), final_tags.cend(), text_area.text) != final_tags.cend()) {
|
||||
final_text_areas.emplace_back(text_area);
|
||||
m_pCtrl->click(text_area.rect);
|
||||
Sleep(300);
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -235,6 +235,10 @@ bool asst::Configer::_load(const std::string& filename)
|
||||
|
||||
m_handles.emplace(name, std::move(emulator_info));
|
||||
}
|
||||
|
||||
for (json::value& rep : root["ocrReplace"].as_array()) {
|
||||
m_ocr_replace.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string());
|
||||
}
|
||||
}
|
||||
catch (json::exception& e) {
|
||||
DebugTraceError("Load config json error!", e.what());
|
||||
|
||||
@@ -18,9 +18,14 @@
|
||||
"controlDelayRange_Doc": "点击随机延时:每次点击操作会进行随机延时,降低封号风险(好像也没听说过谁被封号的)。格式为 [ 最小延时, 最大延时 ],单位为毫秒。例如想设置3~5秒延时,即修改为[ 3000, 5000 ],默认0~0",
|
||||
"ocrGpuIndex": -1,
|
||||
"ocrGpuIndex_Doc": "OcrLite使用GPU编号,-1(使用CPU)/0(使用GPU0)/1(使用GPU1)/...,GPU选择失败时,则使用CPU进行计算。默认-1",
|
||||
"ocrThreadNumber": 4,
|
||||
"ocrThreadNumber": 16,
|
||||
"ocrThreadNumber_Doc": "OcrLite线程数量。默认4"
|
||||
},
|
||||
"ocrReplace": [
|
||||
[ "千员", "干员" ],
|
||||
[ "沮击", "狙击" ],
|
||||
[ "泪击", "狙击" ]
|
||||
],
|
||||
"handle_Doc": "下面的和模拟器窗口捕获逻辑有关,不需要修改",
|
||||
"handle": {
|
||||
"BlueStacks": {
|
||||
@@ -476,6 +481,13 @@
|
||||
"threshold": 0,
|
||||
"type": "stop",
|
||||
"next": []
|
||||
},
|
||||
"RecruitTime": {
|
||||
"template": "RecruitTimeReduce.png",
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"Stop"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
resource/template/RecruitTimeReduce.png
Normal file
BIN
resource/template/RecruitTimeReduce.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
Reference in New Issue
Block a user