mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
feat: 优化 without_det,使用 OcrWithPreprocessImageAnalyzer
This commit is contained in:
@@ -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);
|
||||
@@ -120,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,28 +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;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user