From bb4cedd805afc9ed4101ca1a75bb11d7bb21cd1b Mon Sep 17 00:00:00 2001 From: Sallee1 <885331635@qq.com> Date: Thu, 1 Jun 2023 21:38:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=BD=BB=E5=BA=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E4=BC=9A=E8=BF=94=E5=9B=9Enan=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cvAutoTrack/src/match/surf/SurfMatch.cpp | 41 ++++++++++++++++-------- cvAutoTrack/src/utils/Utils.cpp | 10 +++--- cvAutoTrack/src/utils/Utils.h | 2 +- cvAutoTrack/src/version/version_tag.tag | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/cvAutoTrack/src/match/surf/SurfMatch.cpp b/cvAutoTrack/src/match/surf/SurfMatch.cpp index e029083b..e006455f 100644 --- a/cvAutoTrack/src/match/surf/SurfMatch.cpp +++ b/cvAutoTrack/src/match/surf/SurfMatch.cpp @@ -132,10 +132,7 @@ void SurfMatch::match() if (!isContinuity) { pos = match_no_continuity(calc_is_faile); - if (std::isnan(pos.x) || std::isnan(pos.y)) - { - calc_is_faile = true; //如果pos是nan,则算匹配失败 - } + // 没有有效结果,结束 if (calc_is_faile) { @@ -151,10 +148,6 @@ void SurfMatch::match() bool calc_continuity_is_faile = false; pos = match_continuity(calc_continuity_is_faile); - if (std::isnan(pos.x) || std::isnan(pos.y)) - { - calc_continuity_is_faile = true; //如果pos是nan,则算匹配失败 - } if (!calc_continuity_is_faile) { isContinuity = true; @@ -168,7 +161,7 @@ void SurfMatch::match() return; } } - + last_pos = pos; is_success_match = true; } @@ -287,7 +280,11 @@ cv::Point2d match_all_map(Match& matcher, const cv::Mat& map_mat, const cv::Mat& return all_map_pos; } // 从最佳匹配结果中剔除异常点计算角色位置返回 - all_map_pos = TianLi::Utils::SPC(lisx, lisy); + if (!TianLi::Utils::SPC(lisx, lisy, all_map_pos)) + { + calc_is_faile = true; + return all_map_pos; + } return all_map_pos; } @@ -362,7 +359,13 @@ cv::Point2d SurfMatch::match_continuity_on_city(bool& calc_continuity_is_faile) isOnCity = judgesIsOnCity(keypoint_on_city_list,0.5); //大地图放大了2倍,所以小地图坐标也要这样处理 - cv::Point2d pos_continuity_on_city = TianLi::Utils::SPC(lisx, lisy); + cv::Point2d pos_continuity_on_city; + + if (! TianLi::Utils::SPC(lisx, lisy, pos_continuity_on_city)) + { + calc_continuity_is_faile = true; + return pos_continuity_on_city; + } pos_continuity_on_city.x = (pos_continuity_on_city.x - someMap.cols / 2.0) / 2.0; pos_continuity_on_city.y = (pos_continuity_on_city.y - someMap.rows / 2.0) / 2.0; @@ -433,9 +436,14 @@ cv::Point2d SurfMatch::match_continuity_not_on_city(bool& calc_continuity_is_fai if (!judgesIsOnCity(keypoint_not_on_city_list, MAP_BOTH_SCALE_RATE)) { isOnCity = false; - cv::Point2d p = TianLi::Utils::SPC(lisx, lisy); + cv::Point2d p; + if (!TianLi::Utils::SPC(lisx, lisy, p)) + { + calc_continuity_is_faile = true; + return pos_not_on_city; + } pos_not_on_city = cv::Point2d(p.x + pos.x - real_some_map_size_r, p.y + pos.y - real_some_map_size_r); - return pos_not_on_city; + return pos_not_on_city; } cv::Point2d pos_on_city; @@ -484,7 +492,12 @@ cv::Point2d SurfMatch::match_continuity_not_on_city(bool& calc_continuity_is_fai isOnCity = judgesIsOnCity(keypoint_on_city_list, 0.5); - cv::Point2d p = TianLi::Utils::SPC(list_x_on_city, list_y_on_city); + cv::Point2d p; + if (!TianLi::Utils::SPC(list_x_on_city, list_y_on_city, p)) + { + calc_continuity_is_faile = true; + return pos_on_city; + } double x = (p.x - someMap.cols / 2.0) / 2.0; double y = (p.y - someMap.rows / 2.0) / 2.0; diff --git a/cvAutoTrack/src/utils/Utils.cpp b/cvAutoTrack/src/utils/Utils.cpp index 14917534..d9ddf6fa 100644 --- a/cvAutoTrack/src/utils/Utils.cpp +++ b/cvAutoTrack/src/utils/Utils.cpp @@ -164,9 +164,8 @@ namespace TianLi::Utils } } - cv::Point2d SPC(std::vector lisx, std::vector lisy) + bool SPC(std::vector lisx, std::vector lisy, cv::Point2d& out) { - cv::Point2d pos; double meanx = std::accumulate(lisx.begin(), lisx.end(), 0.0) / lisx.size(); double meany = std::accumulate(lisy.begin(), lisy.end(), 0.0) / lisy.size(); double x = meanx; @@ -204,13 +203,14 @@ namespace TianLi::Utils } x = sumx / numx; y = sumy / numy; - pos = cv::Point2d(x, y); + out = cv::Point2d(x, y); } else { - pos = cv::Point2d(x, y); + out = cv::Point2d(); + return 0; } - return pos; + return true; } int getMaxID(double lis[], int len) diff --git a/cvAutoTrack/src/utils/Utils.h b/cvAutoTrack/src/utils/Utils.h index 828cce49..cebcf0a1 100644 --- a/cvAutoTrack/src/utils/Utils.h +++ b/cvAutoTrack/src/utils/Utils.h @@ -11,7 +11,7 @@ namespace TianLi::Utils cv::Mat get_some_map(const cv::Mat& map, const cv::Point& pos, int size_r); double dis(cv::Point2d p); - cv::Point2d SPC(std::vector lisx, std::vector lisy); + bool SPC(std::vector lisx, std::vector lisy,cv::Point2d& out); double stdev(std::vector list); double stdev(std::vector list); diff --git a/cvAutoTrack/src/version/version_tag.tag b/cvAutoTrack/src/version/version_tag.tag index e84d1c20..da4485d2 100644 --- a/cvAutoTrack/src/version/version_tag.tag +++ b/cvAutoTrack/src/version/version_tag.tag @@ -1 +1 @@ -7.8.69 +7.8.83