From b65596cdd890609a26fba75cd636e2d242bff2f2 Mon Sep 17 00:00:00 2001 From: Yu SuiXian <47711102+GengGode@users.noreply.github.com> Date: Thu, 16 Feb 2023 18:25:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=B8=A6=E9=B1=BC?= =?UTF-8?q?=E5=B1=8F=E4=B8=8B=E6=90=9C=E7=B4=A2calib=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cvAutoTrack/src/AutoTrack.cpp | 2 +- cvAutoTrack/src/AutoTrack.h | 2 +- .../cailb/minimap/genshin.cailb.minimap.cpp | 111 +++++++++++++++++- .../check/paimon/genshin.check.paimon.cpp | 2 + cvAutoTrack/src/match/type/MatchType.h | 2 + cvAutoTrack/src/resources/Resources.h | 8 -- cvAutoTrack/src/version/version_tag.tag | 2 +- 7 files changed, 117 insertions(+), 12 deletions(-) diff --git a/cvAutoTrack/src/AutoTrack.cpp b/cvAutoTrack/src/AutoTrack.cpp index 0f6e9a61..8d9d3dc0 100644 --- a/cvAutoTrack/src/AutoTrack.cpp +++ b/cvAutoTrack/src/AutoTrack.cpp @@ -963,7 +963,7 @@ bool AutoTrack::getMiniMapRefMat() genshin_screen.config.rect_paimon = genshin_paimon.rect_paimon; genshin_screen.config.is_handle_mode = genshin_paimon.is_handle_mode; - genshin_screen.config.rect_minimap_cailb = genshin_minimap_cailb.rect_minimap_cailb; + genshin_screen.config.is_search_mode = genshin_paimon.is_search_mode; if (TianLi::Genshin::Cailb::cailb_minimap(genshin_screen, genshin_minimap) == false) { diff --git a/cvAutoTrack/src/AutoTrack.h b/cvAutoTrack/src/AutoTrack.h index 54fb0957..d5699081 100644 --- a/cvAutoTrack/src/AutoTrack.h +++ b/cvAutoTrack/src/AutoTrack.h @@ -99,7 +99,7 @@ class AutoTrack { GenshinHandle genshin_handle; GenshinScreen genshin_screen; GenshinPaimon genshin_paimon; - GenshinMinimapCailb genshin_minimap_cailb; + //GenshinMinimapCailb genshin_minimap_cailb; GenshinMinimap genshin_minimap; GenshinAvatarPosition genshin_avatar_position; diff --git a/cvAutoTrack/src/genshin/cailb/minimap/genshin.cailb.minimap.cpp b/cvAutoTrack/src/genshin/cailb/minimap/genshin.cailb.minimap.cpp index 208916bb..7689f7b1 100644 --- a/cvAutoTrack/src/genshin/cailb/minimap/genshin.cailb.minimap.cpp +++ b/cvAutoTrack/src/genshin/cailb/minimap/genshin.cailb.minimap.cpp @@ -1,14 +1,123 @@ #include "pch.h" #include "genshin.cailb.minimap.h" +#include "../../../resources/Resources.h" +bool match_minimap_cailb(const GenshinScreen& genshin_screen, GenshinMinimapCailb& out_genshin_minimap_cailb) +{ + static std::vector split_minimap_cailb_template; + static cv::Mat minimap_cailb_template; + static cv::Mat minimap_cailb_template_handle_mode; + static cv::Mat minimap_cailb_template_no_alpha; + static cv::Mat minimap_cailb_template_no_alpha_handle_mode; + static bool is_first = true; + if (is_first) + { + cv::Mat minimap_cailb; + cv::resize(Resources::getInstance().MinimapCailbTemplate, minimap_cailb, cv::Size(), 0.8, 0.8); + cv::split(minimap_cailb, split_minimap_cailb_template); + minimap_cailb_template = split_minimap_cailb_template[3]; + minimap_cailb_template_no_alpha = split_minimap_cailb_template[0]; + cv::resize(split_minimap_cailb_template[3], minimap_cailb_template_handle_mode, cv::Size(), 1 / 1.2, 1 / 1.2, cv::INTER_CUBIC); + cv::resize(split_minimap_cailb_template[3], minimap_cailb_template_no_alpha_handle_mode, cv::Size(), 1.0 / 1.2, 1.0 / 1.2); + is_first = false; + } + + auto giMinimapCailbRef = genshin_screen.img_minimap_cailb_maybe; + auto& rect_origin = genshin_screen.config.rect_minimap_cailb_maybe; + auto& is_handle_mode = genshin_screen.config.is_handle_mode; + + auto& template_not_handle_mode = split_minimap_cailb_template[3]; + auto& template_handle_mode = minimap_cailb_template_handle_mode; + + if (giMinimapCailbRef.empty() || minimap_cailb_template_handle_mode.empty()) return false; + if (giMinimapCailbRef.cols < split_minimap_cailb_template[3].cols || giMinimapCailbRef.rows < split_minimap_cailb_template[3].rows) return false; + + // 设置阈值取值 根据是否使用alpha图层 + double check_match_minimap_cailb_param = out_genshin_minimap_cailb.config.check_match_minimap_cailb_params; + if (genshin_screen.config.is_used_alpha == false) + { + cv::cvtColor(genshin_screen.img_minimap_cailb_maybe, giMinimapCailbRef, cv::COLOR_RGBA2GRAY); + template_not_handle_mode = minimap_cailb_template_no_alpha; + template_handle_mode = minimap_cailb_template_no_alpha_handle_mode; + check_match_minimap_cailb_param = out_genshin_minimap_cailb.config.check_match_minimap_cailb_params_no_alpha; + } + + + std::vector split_minimap_cailb; + cv::split(giMinimapCailbRef, split_minimap_cailb); + + cv::Mat template_result; + if (is_handle_mode) + { + // TODO HOTCODE + cv::matchTemplate(split_minimap_cailb.back(), template_handle_mode, template_result, cv::TM_CCOEFF_NORMED); + } + else + { + // TODO HOTCODE + cv::matchTemplate(split_minimap_cailb.back(), template_not_handle_mode, template_result, cv::TM_CCOEFF_NORMED); + } + + + double minimap_cailb_match_minVal, minimap_cailb_match_maxVal; + cv::Point minimap_cailb_match_minLoc, minimap_cailb_match_maxLoc; + cv::minMaxLoc(template_result, &minimap_cailb_match_minVal, &minimap_cailb_match_maxVal, &minimap_cailb_match_minLoc, &minimap_cailb_match_maxLoc); + + if (minimap_cailb_match_maxVal < check_match_minimap_cailb_param || minimap_cailb_match_maxVal == 1) + { + out_genshin_minimap_cailb.is_visial = false; + } + else + { + out_genshin_minimap_cailb.is_visial = true; + if (is_handle_mode) + { + out_genshin_minimap_cailb.rect_minimap_cailb = cv::Rect(rect_origin.tl() + minimap_cailb_match_maxLoc, template_handle_mode.size()); + } + else + { + out_genshin_minimap_cailb.rect_minimap_cailb = cv::Rect(rect_origin.tl() + minimap_cailb_match_maxLoc, template_not_handle_mode.size()); + } + } + + return true; +} bool cailb_minimap_impl(const GenshinScreen& genshin_screen, GenshinMinimap& out_genshin_minimap) { auto& paimon_rect = genshin_screen.config.rect_paimon; // not find paimon if (paimon_rect.empty()) return false; - + // rect auto minimap_rect = genshin_screen.config.is_handle_mode ? genshin_screen.config.rect_minimap_handle : genshin_screen.config.rect_minimap; + if (genshin_screen.config.is_search_mode) + { + static GenshinMinimapCailb genshin_minimap_cailb; + bool is_find_minimap_cailb = match_minimap_cailb(genshin_screen, genshin_minimap_cailb); + if (is_find_minimap_cailb ==false) + { + return false; + } + auto& minimap_cailb_rect = genshin_minimap_cailb.rect_minimap_cailb; + // 1. 以paimon为基准,计算出minimap的左边界 + auto minimap_left = paimon_rect.x + paimon_rect.width / 2; + // 2. 以minimap_cailb为基准,计算出minimap的右边界 + auto minimap_right = minimap_cailb_rect.x + minimap_cailb_rect.width / 2; + // 3. 以paimon和minimap_cailb为基准,计算出minimap的上边界 + auto minimap_top = (paimon_rect.y + minimap_cailb_rect.y) / 2; + // 4. 计算出minimap的宽度 + auto minimap_width = minimap_right - minimap_left; + // 5. 计算出minimap的高度 + auto minimap_height = minimap_width; + // 6. 计算出minimap的下边界 + auto minimap_bottom = minimap_top + minimap_height; + // 7. 计算出minimap的左上角坐标 + auto minimap_left_top = cv::Point(minimap_left, minimap_top); + // 8. 计算出minimap的右下角坐标 + auto minimap_right_bottom = cv::Point(minimap_right, minimap_bottom); + // 9. 计算出minimap的矩形区域 + minimap_rect = cv::Rect(minimap_left_top, minimap_right_bottom); + } // center point auto minimap_center = cv::Point(minimap_rect.x + (minimap_rect.width) / 2, minimap_rect.y + (minimap_rect.height) / 2); out_genshin_minimap.img_minimap = genshin_screen.img_screen(minimap_rect); diff --git a/cvAutoTrack/src/genshin/check/paimon/genshin.check.paimon.cpp b/cvAutoTrack/src/genshin/check/paimon/genshin.check.paimon.cpp index d4b40c3b..a4bd65c5 100644 --- a/cvAutoTrack/src/genshin/check/paimon/genshin.check.paimon.cpp +++ b/cvAutoTrack/src/genshin/check/paimon/genshin.check.paimon.cpp @@ -99,6 +99,7 @@ bool check_paimon_search_impl(const GenshinScreen& genshin_screen, GenshinPaimon out_genshin_paimon.is_handle_mode = false; out_genshin_paimon.is_visial = true; out_genshin_paimon.rect_paimon = cv::Rect(rect_origin.tl() + paimon_match_maxLoc, paimon_template.size()); + out_genshin_paimon.is_search_mode = true; // 设置匹配派蒙的rect位置为新搜索到的位置 out_genshin_paimon.config.rect_paimon_keypoint = out_genshin_paimon.rect_paimon; return true; @@ -120,6 +121,7 @@ bool check_paimon_search_impl(const GenshinScreen& genshin_screen, GenshinPaimon out_genshin_paimon.is_handle_mode = true; out_genshin_paimon.is_visial = true; out_genshin_paimon.rect_paimon = cv::Rect(rect_origin.tl() + paimon_match_handle_mode_maxLoc, paimon_template_handle_mode.size()); + out_genshin_paimon.is_search_mode = true; // 设置手柄模式下匹配派蒙的rect位置为新搜索到的位置 out_genshin_paimon.config.rect_paimon_keypoint_handle = out_genshin_paimon.rect_paimon; return true; diff --git a/cvAutoTrack/src/match/type/MatchType.h b/cvAutoTrack/src/match/type/MatchType.h index ed8d2079..d69275be 100644 --- a/cvAutoTrack/src/match/type/MatchType.h +++ b/cvAutoTrack/src/match/type/MatchType.h @@ -111,6 +111,7 @@ struct GenshinScreenConfig bool is_used_alpha = true; bool is_handle_mode = false; + bool is_search_mode = false; cv::Rect rect_paimon; cv::Rect rect_minimap_cailb; @@ -165,6 +166,7 @@ struct GenshinPaimon { bool is_visial = false; bool is_handle_mode = false; + bool is_search_mode = false; cv::Rect rect_paimon; GenshinPaimonConfig config; }; diff --git a/cvAutoTrack/src/resources/Resources.h b/cvAutoTrack/src/resources/Resources.h index b9b0aa75..f8bcbab9 100644 --- a/cvAutoTrack/src/resources/Resources.h +++ b/cvAutoTrack/src/resources/Resources.h @@ -21,14 +21,6 @@ class Resources cv::Mat MapTemplate; cv::Mat UID; cv::Mat UIDnumber[10]; - - //struct XmlPtr - //{ - // char* ptr = nullptr; - // int size = 0; - //}; - // - //XmlPtr xmlPtr = { nullptr,0 }; public: void install(); void release(); diff --git a/cvAutoTrack/src/version/version_tag.tag b/cvAutoTrack/src/version/version_tag.tag index 560a4a04..02024362 100644 --- a/cvAutoTrack/src/version/version_tag.tag +++ b/cvAutoTrack/src/version/version_tag.tag @@ -1 +1 @@ -7.5.94 +7.5.97