mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 01:59:33 +08:00
feat: PipelineAnalyzer 支持使用灰度图匹配文字
This commit is contained in:
@@ -604,6 +604,7 @@ struct OcrTaskInfo : public TaskInfo
|
||||
bool is_ascii = false; // 是否启用字符数字模型
|
||||
bool without_det = false; // 是否不使用检测模型
|
||||
bool replace_full = false; // 匹配之后,是否将整个字符串replace(false是只替换match的部分)
|
||||
bool use_raw = true; // 是否使用原始图片进行识别,false则使用灰度图
|
||||
std::vector<std::pair<std::string, std::string>>
|
||||
replace_map; // 部分文字容易识别错,字符串强制replace之后,再进行匹配
|
||||
int bin_threshold_lower = 140;
|
||||
|
||||
@@ -801,6 +801,12 @@ asst::TaskPtr asst::TaskData::generate_ocr_task_info(
|
||||
"binThresholdUpper",
|
||||
ocr_task_info_ptr->bin_threshold_upper,
|
||||
default_ptr->bin_threshold_upper);
|
||||
utils::get_and_check_value_or(
|
||||
name,
|
||||
task_json,
|
||||
"useRaw",
|
||||
ocr_task_info_ptr->use_raw,
|
||||
default_ptr->use_raw);
|
||||
return ocr_task_info_ptr;
|
||||
}
|
||||
|
||||
@@ -1070,8 +1076,8 @@ bool asst::TaskData::syntax_check(std::string_view task_name, const json::value&
|
||||
|
||||
// specific
|
||||
"cache", "fullMatch", "isAscii", "ocrReplace", "rectMove",
|
||||
"replaceFull", "roi", "text", "withoutDet", "binThresholdLower",
|
||||
"binThresholdUpper",
|
||||
"replaceFull", "roi", "text", "withoutDet", "useRaw",
|
||||
"binThresholdLower", "binThresholdUpper",
|
||||
} },
|
||||
{ AlgorithmType::FeatureMatch,
|
||||
{
|
||||
|
||||
@@ -100,6 +100,7 @@ void OCRerConfig::_set_task_info(OcrTaskInfo task_info)
|
||||
m_params.without_det = task_info.without_det;
|
||||
m_params.bin_threshold_lower = task_info.bin_threshold_lower;
|
||||
m_params.bin_threshold_upper = task_info.bin_threshold_upper;
|
||||
m_params.use_raw = task_info.use_raw;
|
||||
|
||||
_set_roi(task_info.roi);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
bool replace_full = false;
|
||||
bool without_det = false;
|
||||
bool use_char_model = false;
|
||||
bool use_raw = false;
|
||||
|
||||
int bin_threshold_lower = 140;
|
||||
int bin_threshold_upper = 255;
|
||||
|
||||
@@ -40,8 +40,10 @@ RegionOCRer::ResultOpt RegionOCRer::analyze() const
|
||||
#endif // ASST_DEBUG
|
||||
new_roi = correct_rect(new_roi, m_roi);
|
||||
|
||||
auto config = m_params;
|
||||
auto use_raw = config.use_raw;
|
||||
OCRer ocr_analyzer;
|
||||
if (m_use_raw) {
|
||||
if (use_raw) {
|
||||
ocr_analyzer = OCRer(m_image, new_roi);
|
||||
}
|
||||
else {
|
||||
@@ -51,7 +53,6 @@ RegionOCRer::ResultOpt RegionOCRer::analyze() const
|
||||
ocr_analyzer = OCRer(bin3, bounding_rect);
|
||||
}
|
||||
|
||||
auto config = m_params;
|
||||
config.without_det = true;
|
||||
ocr_analyzer.set_params(std::move(config));
|
||||
|
||||
@@ -60,7 +61,7 @@ RegionOCRer::ResultOpt RegionOCRer::analyze() const
|
||||
return std::nullopt;
|
||||
}
|
||||
m_result = result->front();
|
||||
if (!m_use_raw) {
|
||||
if (!use_raw) {
|
||||
m_result.rect.x += m_roi.x;
|
||||
m_result.rect.y += m_roi.y;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
|
||||
ResultOpt analyze() const;
|
||||
|
||||
void set_use_raw(bool use_raw) { m_use_raw = use_raw; }
|
||||
void set_use_raw(bool use_raw) { m_params.use_raw = use_raw; }
|
||||
|
||||
// FIXME: 老接口太难重构了,先弄个这玩意兼容下,后续慢慢全删掉
|
||||
const auto& get_result() const noexcept { return m_result; }
|
||||
@@ -31,6 +31,5 @@ protected:
|
||||
private:
|
||||
// FIXME: 老接口太难重构了,先弄个这玩意兼容下,后续慢慢全删掉
|
||||
mutable Result m_result;
|
||||
bool m_use_raw = true;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user