rft: 重构战斗中击杀识别, 击杀图标匹配使用高斯模糊预处理 (#15868)

* Revert "chore: Auto Templates Optimization"

This reverts commit f9b866000d.

Revert "fix: 沟槽的 yj 怎么有倒计时的时候击杀数图标都不一样"

This reverts commit fd718fa355.

Revert "chore: Auto Templates Optimization"

This reverts commit 4855537bd3.

Revert "perf: 优化击杀数模板图"

This reverts commit e4ba0f1efe.

* rft: 重构战斗中击杀识别

* chore: remove debug code

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* chore: roi恢复

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This commit is contained in:
Status102
2026-02-28 11:51:18 +08:00
committed by GitHub
parent 8372c35f4c
commit ff0d76b031
5 changed files with 49 additions and 22 deletions

View File

@@ -3771,7 +3771,7 @@
"algorithm": "OcrDetect",
"isAscii": true,
"text": [],
"roi": [40, -20, 100, 40],
"roi": [50, 0, 100, 40],
"useRaw": false,
"specialParams_doc": "Kill区域变化阈值, 模板匹配, 100=1.0; 正常在 0.997-1 之间波动, 少有0.995; _5->_6 的分数最高, 可达0.94",
"specialParams": [98]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -273,17 +273,27 @@ bool BattlefieldMatcher::kills_flag_analyze() const
BattlefieldMatcher::MatchResult<std::pair<int, int>> BattlefieldMatcher::kills_analyze() const
{
if (hit_kills_cache()) {
auto [hit_cache, flag_rect] = hit_kills_cache();
if (hit_cache) {
return { .status = MatchStatus::HitCache };
}
TemplDetOCRer kills_analyzer(m_image);
kills_analyzer.set_task_info("BattleKillsFlag", "BattleKills");
kills_analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
auto kills_opt = kills_analyzer.analyze();
if (flag_rect == std::nullopt) {
LogWarn << __FUNCTION__ << "kill flag not found";
return {};
}
const auto& ocr_task = Task.get<OcrTaskInfo>("BattleKills");
RegionOCRer flag_analyzer(m_image);
flag_analyzer.set_roi(flag_rect->move(ocr_task->roi));
flag_analyzer.set_use_char_model(ocr_task->is_ascii);
flag_analyzer.set_use_raw(ocr_task->use_raw);
flag_analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
auto kills_opt = flag_analyzer.analyze();
if (!kills_opt) {
return {};
}
const std::string& kills_text = kills_opt->front().text;
const std::string& kills_text = kills_opt->text;
if (kills_text.empty()) {
return {};
}
@@ -341,19 +351,36 @@ BattlefieldMatcher::MatchResult<std::pair<int, int>> BattlefieldMatcher::kills_a
return { .value = std::make_pair(kills, total_kills), .status = MatchStatus::Success };
}
bool asst::BattlefieldMatcher::hit_kills_cache() const
std::pair<bool, std::optional<Rect>> asst::BattlefieldMatcher::hit_kills_cache() const
{
if (m_image_prev.empty() || m_image.cols != m_image_prev.cols || m_image.rows != m_image_prev.rows) {
return false;
}
Matcher flag_match(m_image);
flag_match.set_task_info("BattleKillsFlag");
const auto& flag_task = Task.get<MatchTaskInfo>("BattleKillsFlag");
cv::Mat template_image = TemplResource::get_instance().get_templ("BattleKillsFlag.png");
cv::Mat match_image = make_roi(m_image, flag_task->roi);
// 对模板图和截图都进行一次模糊减少yj缩放对文字及细节的影响提升命中率
cv::Mat template_blur, image_blur;
cv::GaussianBlur(template_image, template_blur, cv::Size(3, 3), 0);
cv::GaussianBlur(match_image, image_blur, cv::Size(3, 3), 0);
Matcher flag_match(image_blur);
flag_match.set_mask_ranges(flag_task->mask_ranges);
flag_match.set_roi({ 0, 0, flag_task->roi.width, flag_task->roi.height });
flag_match.set_templ(template_blur);
flag_match.set_method(MatchMethod::Ccoeff);
flag_match.set_threshold(flag_task->templ_thresholds);
if (!flag_match.analyze()) {
return false;
return { false, std::nullopt };
}
const auto& flag_rect = flag_match.get_result().rect;
const auto& task = Task.get("BattleKills");
const auto& roi = flag_rect.move(task->roi);
auto flag_rect = flag_match.get_result().rect;
flag_rect.x += flag_task->roi.x;
flag_rect.y += flag_task->roi.y;
if (m_image_prev.empty() || m_image.size != m_image_prev.size) {
return { false, flag_rect };
}
const auto& ocr_task = Task.get<OcrTaskInfo>("BattleKills");
const auto& roi = flag_rect.move(ocr_task->roi);
cv::Mat kills_image_cache = make_roi(m_image_prev, roi);
cv::Mat kills_image = make_roi(m_image, roi);
@@ -365,8 +392,8 @@ bool asst::BattlefieldMatcher::hit_kills_cache() const
cv::minMaxLoc(match, nullptr, &mark);
// 正常在 0.997-1 之间波动, 少有0.995
// _5->_6 的分数最高, 可达0.94
const double threshold = static_cast<double>(task->special_params[0]) / 100;
return mark > threshold;
const double threshold = static_cast<double>(ocr_task->special_params[0]) / 100;
return { mark > threshold, flag_rect };
}
bool BattlefieldMatcher::cost_symbol_analyze() const
@@ -397,7 +424,7 @@ BattlefieldMatcher::MatchResult<int> BattlefieldMatcher::costs_analyze() const
bool asst::BattlefieldMatcher::hit_costs_cache() const
{
if (m_image_prev.empty() || m_image.cols != m_image_prev.cols || m_image.rows != m_image_prev.rows) {
if (m_image_prev.empty() || m_image.size != m_image_prev.size) {
return false;
}
const auto& task = Task.get("BattleCostData");

View File

@@ -69,7 +69,7 @@ protected:
MatchResult<std::pair<int, int>> kills_analyze() const; // 识别击杀数
// 识别是否持有费用是否命中缓存
bool hit_kills_cache() const;
std::pair<bool, std::optional<Rect>> hit_kills_cache() const;
bool cost_symbol_analyze() const; // 识别费用左侧图标
MatchResult<int> costs_analyze() const; // 识别费用
// 识别是否持有费用是否命中缓存

View File

@@ -2653,7 +2653,7 @@
"resource/template/Battle/BattleFlag/EndOfAction": "3a4e90ae88d0ff83304c793bd05695335888d67d0b3224066a22b465c5f53f0b",
"resource/template/Battle/BattleFlag/BattleSpeedUp": "f81a6ea54970ec3fdfbea14c2887e067e60ca3ba7d3c7168da7b19c5a62c91ca",
"resource/template/Battle/BattleFlag/BattleSkillReadyOnClick-TopView2": "9de4d366eab581c30dfde35346a94197727a6397e7c8f99da07a828f70b89607",
"resource/template/Battle/BattleFlag/BattleKillsFlag": "e167dd5a8ef789c7626eb463110d1899d1987a84003ff9d15fa9a4ddf34103f5",
"resource/template/Battle/BattleFlag/BattleKillsFlag": "7b5db70e0fd69ea0f09db643d6e3c31999fe521a6439fe3ab47aa85a014f3b59",
"resource/template/Battle/BattleFlag/AbandonAction": "052a60fec1eb98ff3ab12814e40426ff682377b89c9ee844d3cff210c662559e",
"resource/template/Battle/BattleFlag/BattleSkillReady": "6dcb381619811d91419ffda02fa4764908e3d61107abe2ecd0c8e92b631a6746",
"resource/template/Battle/BattleFlag/PrtsErrorConfirm": "57ce7a88d0a231a8b77ea24c7f69e4cce65038095dda68d6782afddbcd37566e",