Skip to content

Commit

Permalink
fix:彻底修复坐标会返回nan的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Sallee1 committed Jun 1, 2023
1 parent 1af582b commit bb4cedd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
41 changes: 27 additions & 14 deletions cvAutoTrack/src/match/surf/SurfMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -168,7 +161,7 @@ void SurfMatch::match()
return;
}
}

last_pos = pos;
is_success_match = true;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions cvAutoTrack/src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ namespace TianLi::Utils
}
}

cv::Point2d SPC(std::vector<double> lisx, std::vector<double> lisy)
bool SPC(std::vector<double> lisx, std::vector<double> 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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cvAutoTrack/src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> lisx, std::vector<double> lisy);
bool SPC(std::vector<double> lisx, std::vector<double> lisy,cv::Point2d& out);

double stdev(std::vector<double> list);
double stdev(std::vector<cv::Point2d> list);
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.8.69
7.8.83

0 comments on commit bb4cedd

Please sign in to comment.