Merge pull request #2717 from MaaAssistantArknights/feat/det_ascii

feat: 优化 isAscii、withoutDet 参数的处理
This commit is contained in:
MistEO
2022-11-12 14:53:53 +08:00
committed by GitHub
12 changed files with 52 additions and 56 deletions

View File

@@ -3818,6 +3818,7 @@
},
"CreditShop-CreditOcr": {
"algorithm": "OcrDetect",
"isAscii": true,
"text": [],
"roi": [
1147,
@@ -3929,6 +3930,7 @@
"RecruitTimerH": {
"Doc": "识别公招小时数",
"algorithm": "OcrDetect",
"isAscii": true,
"roi": [
400,
180,
@@ -3950,6 +3952,7 @@
"RecruitTimerM": {
"Doc": "识别公招分钟数",
"algorithm": "OcrDetect",
"isAscii": true,
"roi": [
570,
180,
@@ -6057,6 +6060,7 @@
},
"BattleKills": {
"algorithm": "OcrDetect",
"isAscii": true,
"text": [],
"roi": [
50,
@@ -6067,6 +6071,7 @@
},
"BattleCostData": {
"algorithm": "OcrDetect",
"isAscii": true,
"text": [],
"roi": [
1196,
@@ -6502,6 +6507,7 @@
"StageDrops-StageName": {
"algorithm": "OcrDetect",
"action": "DoNothing",
"isAscii": true,
"text": [],
"ocrReplace": [
[
@@ -6644,6 +6650,7 @@
},
"NumberOcrReplace": {
"algorithm": "OcrDetect",
"isAscii": true,
"text": [],
"ocrReplace": [
[
@@ -8761,15 +8768,15 @@
"algorithm": "OcrDetect",
"action": "ClickSelf",
"cache": false,
"withoutDet": true,
"roi": [
880,
200,
220,
120
210,
140,
36
],
"text": [
"活用",
"再利用"
"活用安全屋"
],
"preDelay": 500,
"next": [
@@ -9013,33 +9020,29 @@
"action": "DoNothing",
"postDelay": 100
},
"RoguelikeRecruitElite0": {
"roi": [
"RoguelikeRecruitElite": {
"Doc": "base_task",
"template": "empty.png",
"rectMove": [
-170,
-60,
60,
50
]
},
"RoguelikeRecruitElite0": {
"baseTask": "RoguelikeRecruitElite"
},
"RoguelikeRecruitElite1": {
"roi": [
-170,
-60,
60,
50
]
"baseTask": "RoguelikeRecruitElite"
},
"RoguelikeRecruitElite2": {
"roi": [
-170,
-60,
60,
50
]
"baseTask": "RoguelikeRecruitElite"
},
"RoguelikeRecruitLevel": {
"template": "empty.png",
"roi": [
"algorithm": "JustReturn",
"rectMove_Doc": "肉鸽招募时检测等级用相对flag的位移",
"rectMove": [
-171,
0,
15,

View File

@@ -441,7 +441,6 @@ bool asst::BattleImageAnalyzer::kills_analyze()
OcrWithFlagTemplImageAnalyzer kills_analyzer(m_image);
kills_analyzer.set_task_info("BattleKillsFlag", "BattleKills");
kills_analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
kills_analyzer.set_use_char_model(true);
if (!kills_analyzer.analyze()) {
return false;
@@ -507,7 +506,6 @@ bool asst::BattleImageAnalyzer::cost_analyze()
OcrWithPreprocessImageAnalyzer cost_analyzer(m_image);
cost_analyzer.set_task_info("BattleCostData");
cost_analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
cost_analyzer.set_use_char_model(true);
if (!cost_analyzer.analyze()) {
return false;

View File

@@ -288,7 +288,6 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi)
analyzer.set_roi(ocr_roi);
analyzer.set_expansion(1);
analyzer.set_threshold(task_ptr->mask_range.first, task_ptr->mask_range.second);
analyzer.set_use_char_model(true);
if (!analyzer.analyze()) {
return 0;

View File

@@ -91,11 +91,6 @@ void asst::OcrImageAnalyzer::set_use_cache(bool is_use) noexcept
m_use_cache = is_use;
}
void asst::OcrImageAnalyzer::set_without_det(bool without_det) noexcept
{
m_without_det = without_det;
}
void asst::OcrImageAnalyzer::set_required(std::vector<std::string> required) noexcept
{
m_required = std::move(required);
@@ -112,6 +107,7 @@ void asst::OcrImageAnalyzer::set_task_info(OcrTaskInfo task_info) noexcept
m_full_match = task_info.full_match;
m_replace = std::move(task_info.replace_map);
m_use_cache = task_info.cache;
m_use_char_model = task_info.is_ascii;
if (m_use_cache && !m_region_of_appeared.empty()) {
m_roi = m_region_of_appeared;
@@ -119,7 +115,7 @@ void asst::OcrImageAnalyzer::set_task_info(OcrTaskInfo task_info) noexcept
}
else {
set_roi(task_info.roi);
m_without_det = false;
m_without_det = task_info.without_det;
}
}

View File

@@ -31,7 +31,6 @@ namespace asst
virtual void set_task_info(const std::string& task_name);
virtual void set_use_cache(bool is_use) noexcept;
virtual void set_without_det(bool without_det) noexcept;
virtual void set_region_of_appeared(Rect region) noexcept;
virtual void set_use_char_model(bool enable) noexcept;

View File

@@ -5,6 +5,7 @@
#include "General/MatchImageAnalyzer.h"
#include "General/OcrImageAnalyzer.h"
#include "General/OcrWithPreprocessImageAnalyzer.h"
#include "RuntimeStatus.h"
#include "TaskData.h"
#include "Utils/Logger.hpp"
@@ -71,29 +72,34 @@ bool asst::ProcessTaskImageAnalyzer::ocr_analyze(const std::shared_ptr<TaskInfo>
// }
// }
//}
if (!m_ocr_analyzer) {
m_ocr_analyzer = std::make_unique<OcrImageAnalyzer>(m_image);
std::unique_ptr<OcrImageAnalyzer>* analyzer_ptr = nullptr;
if (ocr_task_ptr->without_det) {
if (!m_ocr_with_preprocess_analyzer) {
m_ocr_with_preprocess_analyzer = std::make_unique<OcrWithPreprocessImageAnalyzer>(m_image);
}
analyzer_ptr = decltype(analyzer_ptr)(&m_ocr_with_preprocess_analyzer);
}
m_ocr_analyzer->set_region_of_appeared(Rect());
m_ocr_analyzer->set_without_det(ocr_task_ptr->without_det);
m_ocr_analyzer->set_task_info(ocr_task_ptr);
m_ocr_analyzer->set_use_char_model(ocr_task_ptr->is_ascii);
auto region_opt = m_status->get_rect(ocr_task_ptr->name);
if (region_opt) {
m_ocr_analyzer->set_region_of_appeared(region_opt.value());
else {
if (!m_ocr_analyzer) {
m_ocr_analyzer = std::make_unique<OcrImageAnalyzer>(m_image);
}
analyzer_ptr = &m_ocr_analyzer;
}
bool ret = m_ocr_analyzer->analyze();
(*analyzer_ptr)->set_region_of_appeared(m_status->get_rect(ocr_task_ptr->name).value_or(Rect()));
(*analyzer_ptr)->set_task_info(ocr_task_ptr);
bool ret = (*analyzer_ptr)->analyze();
if (ret) {
m_ocr_analyzer->sort_result_by_required();
const auto& ocr_result = m_ocr_analyzer->get_result();
(*analyzer_ptr)->sort_result_by_required();
const auto& ocr_result = (*analyzer_ptr)->get_result();
auto& res = ocr_result.front();
m_result = ocr_task_ptr;
m_result_rect = res.rect;
m_status->set_rect(ocr_task_ptr->name, m_result_rect);
// m_ocr_cache.insert(m_ocr_cache.end(), ocr_result.begin(), ocr_result.end());
Log.trace("ProcessTaskImageAnalyzer::ocr_analyze | found", res.to_string());
Log.trace(__FUNCTION__, "| found", res);
}
return ret;
}

View File

@@ -10,6 +10,7 @@
namespace asst
{
class OcrImageAnalyzer;
class OcrWithPreprocessImageAnalyzer;
class MatchImageAnalyzer;
class RuntimeStatus;
@@ -41,6 +42,7 @@ namespace asst
void reset() noexcept;
std::unique_ptr<OcrImageAnalyzer> m_ocr_analyzer;
std::unique_ptr<OcrWithPreprocessImageAnalyzer> m_ocr_with_preprocess_analyzer;
std::unique_ptr<MatchImageAnalyzer> m_match_analyzer;
std::vector<std::string> m_tasks_name;
std::shared_ptr<TaskInfo> m_result = nullptr;

View File

@@ -67,7 +67,7 @@ int asst::RoguelikeRecruitImageAnalyzer::match_elite(const Rect& raw_roi)
MatchImageAnalyzer analyzer(m_image);
auto task_ptr = Task.get(task_name);
analyzer.set_task_info(task_ptr);
analyzer.set_roi(raw_roi.move(task_ptr->roi));
analyzer.set_roi(raw_roi.move(task_ptr->rect_move));
if (!analyzer.analyze()) {
continue;
@@ -85,12 +85,10 @@ int asst::RoguelikeRecruitImageAnalyzer::match_level(const cv::Mat& image, const
{
LogTraceFunction;
auto task_ptr = Task.get("RoguelikeRecruitLevel");
OcrWithPreprocessImageAnalyzer analyzer(image, raw_roi.move(task_ptr->roi));
auto& replace = Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map;
analyzer.set_replace(replace);
OcrWithPreprocessImageAnalyzer analyzer(image);
analyzer.set_task_info("NumberOcrReplace");
analyzer.set_roi(raw_roi.move(Task.get("RoguelikeRecruitLevel")->rect_move));
analyzer.set_expansion(1);
analyzer.set_use_char_model(true);
if (!analyzer.analyze()) {
return -1;

View File

@@ -47,7 +47,6 @@ bool asst::StageDropsImageAnalyzer::analyze_stage_code()
OcrImageAnalyzer analyzer(m_image);
analyzer.set_task_info("StageDrops-StageName");
analyzer.set_use_char_model(true);
if (!analyzer.analyze()) {
return false;
@@ -519,7 +518,6 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
analyzer.set_roi(Rect(quantity_roi.x + far_left, quantity_roi.y, far_right - far_left, quantity_roi.height));
analyzer.set_expansion(1);
analyzer.set_threshold(task_ptr->mask_range.first, task_ptr->mask_range.second);
analyzer.set_use_char_model(true);
if (!analyzer.analyze()) {
return 0;

View File

@@ -53,7 +53,7 @@ int asst::DrGrandetTaskPlugin::analyze_time_left()
analyzer.set_task_info("DrGrandetUseOriginiums");
analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
// 这里是汉字和数字混合的用不了单独的en模型
// analyzer.set_use_char_model(true);
analyzer.set_use_char_model(false);
if (!analyzer.analyze()) {
return -1;

View File

@@ -595,7 +595,6 @@ bool asst::AutoRecruitTask::check_timer(int minutes_expected)
OcrImageAnalyzer hour_ocr(image);
hour_ocr.set_task_info("RecruitTimerH");
hour_ocr.set_replace(replace_map);
hour_ocr.set_use_char_model(true);
if (!hour_ocr.analyze()) return false;
std::string desired_hour_str = std::string("0") + std::to_string(minutes_expected / 60);
if (hour_ocr.get_result().front().text != desired_hour_str) return false;
@@ -606,7 +605,6 @@ bool asst::AutoRecruitTask::check_timer(int minutes_expected)
OcrImageAnalyzer minute_ocr(image);
minute_ocr.set_task_info("RecruitTimerM");
minute_ocr.set_replace(replace_map);
minute_ocr.set_use_char_model(true);
if (!minute_ocr.analyze()) return false;
std::string desired_minute_str = std::to_string((minutes_expected % 60) / 10) + "0";
if (minute_ocr.get_result().front().text != desired_minute_str) return false;

View File

@@ -36,7 +36,6 @@ int asst::CreditShoppingTask::credit_ocr()
OcrImageAnalyzer credit_analyzer(credit_image);
credit_analyzer.set_task_info("CreditShop-CreditOcr");
credit_analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
credit_analyzer.set_use_char_model(true);
if (!credit_analyzer.analyze()) {
Log.trace("ERROR:!credit_analyzer.analyze():");