Skip to content

Commit

Permalink
fix: 修复特征匹配中透视转换崩溃问题
Browse files Browse the repository at this point in the history
fix #275
  • Loading branch information
MistEO committed Jul 25, 2024
1 parent 19fb8f2 commit 7b1fc55
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions source/MaaFramework/Vision/FeatureMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,19 @@ FeatureMatcher::ResultsVec FeatureMatcher::feature_postproc(
return {};
}

cv::Mat H = cv::findHomography(obj, scene, cv::RANSAC);
cv::Mat homography = cv::findHomography(obj, scene, cv::RHO);

if (homography.empty()) {
LogTrace << name_ << VAR(uid_) << "Homography is empty";
return {};
}

std::array<cv::Point2d, 4> obj_corners = { cv::Point2d(0, 0),
cv::Point2d(templ_cols, 0),
cv::Point2d(templ_cols, templ_rows),
cv::Point2d(0, templ_rows) };
std::array<cv::Point2d, 4> scene_corners;
cv::perspectiveTransform(obj_corners, scene_corners, H);
cv::perspectiveTransform(obj_corners, scene_corners, homography);

double x = std::min(
{ scene_corners[0].x, scene_corners[1].x, scene_corners[2].x, scene_corners[3].x });
Expand Down Expand Up @@ -336,4 +341,4 @@ void FeatureMatcher::sort_(ResultsVec& results) const
}
}

MAA_VISION_NS_END
MAA_VISION_NS_END

0 comments on commit 7b1fc55

Please sign in to comment.