From 7b1fc559b8abee9ed7681f77fb481e4a2f016f1a Mon Sep 17 00:00:00 2001 From: MistEO Date: Thu, 25 Jul 2024 23:45:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=89=B9=E5=BE=81?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E4=B8=AD=E9=80=8F=E8=A7=86=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix https://github.com/MaaXYZ/MaaFramework/issues/275 --- source/MaaFramework/Vision/FeatureMatcher.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/MaaFramework/Vision/FeatureMatcher.cpp b/source/MaaFramework/Vision/FeatureMatcher.cpp index 1050801b7..349c8e676 100644 --- a/source/MaaFramework/Vision/FeatureMatcher.cpp +++ b/source/MaaFramework/Vision/FeatureMatcher.cpp @@ -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 obj_corners = { cv::Point2d(0, 0), cv::Point2d(templ_cols, 0), cv::Point2d(templ_cols, templ_rows), cv::Point2d(0, templ_rows) }; std::array 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 }); @@ -336,4 +341,4 @@ void FeatureMatcher::sort_(ResultsVec& results) const } } -MAA_VISION_NS_END \ No newline at end of file +MAA_VISION_NS_END