Skip to content

Commit

Permalink
fix:修复带鱼屏下搜索calib位置
Browse files Browse the repository at this point in the history
  • Loading branch information
GengGode committed Feb 16, 2023
1 parent 3acd0b8 commit b65596c
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cvAutoTrack/src/AutoTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion cvAutoTrack/src/AutoTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
111 changes: 110 additions & 1 deletion cvAutoTrack/src/genshin/cailb/minimap/genshin.cailb.minimap.cpp
Original file line number Diff line number Diff line change
@@ -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<cv::Mat> 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<cv::Mat> 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);
Expand Down
2 changes: 2 additions & 0 deletions cvAutoTrack/src/genshin/check/paimon/genshin.check.paimon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions cvAutoTrack/src/match/type/MatchType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
8 changes: 0 additions & 8 deletions cvAutoTrack/src/resources/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion cvAutoTrack/src/version/version_tag.tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.5.94
7.5.97

0 comments on commit b65596c

Please sign in to comment.