From 6c07df30284360898e90dc3e87abb9eeb47d7bd8 Mon Sep 17 00:00:00 2001 From: asantamaria <asantamaria@iri.upc.edu> Date: Fri, 18 May 2018 18:07:59 +0200 Subject: [PATCH] Add nnSymmetryTest. No gtest yet --- src/matchers/matcher_base.cpp | 26 ++++++++++++++++++++++++++ src/matchers/matcher_base.h | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/src/matchers/matcher_base.cpp b/src/matchers/matcher_base.cpp index 2affc12..84e8d41 100644 --- a/src/matchers/matcher_base.cpp +++ b/src/matchers/matcher_base.cpp @@ -308,6 +308,32 @@ void MatcherBase::ransacTest(const KeyPointVector& _raw_kps1, } } +void MatcherBase::nnSymmetryTest(const std::vector<DMatchVector>& _matches1, + const std::vector<DMatchVector>& _matches2, + DMatchVector& _sym_matches) +{ + // for all matches image 1 -> image 2 + for (std::vector<DMatchVector>::const_iterator itM1 = _matches1.begin(); itM1 != _matches1.end(); ++itM1) + { + if (itM1->size() < 2) // ignore deleted matches + continue; + + // for all matches image 2 -> image 1 + for (std::vector<DMatchVector>::const_iterator itM2 = _matches2.begin(); itM2 != _matches2.end(); ++itM2) + { + if (itM2->size() < 2) // ignore deleted matches + continue; + + // Match symmetry test + if ((*itM1)[0].queryIdx == (*itM2)[0].trainIdx && (*itM2)[0].queryIdx == (*itM1)[0].trainIdx) + { + // add symmetrical match + _sym_matches.push_back(cv::DMatch((*itM1)[0].queryIdx, (*itM1)[0].trainIdx, (*itM1)[0].distance)); + break; // next match in image 1 -> image 2 + } + } + } +} cv::Mat MatcherBase::drawMatches(const cv::Mat _img1, const cv::Mat _img2, KeyPointVector _kpts12_img1, KeyPointVector _kpts12_img2) { diff --git a/src/matchers/matcher_base.h b/src/matchers/matcher_base.h index 966c147..224d2c5 100644 --- a/src/matchers/matcher_base.h +++ b/src/matchers/matcher_base.h @@ -134,6 +134,11 @@ class MatcherBase : public VUBase, public std::enable_shared_from_this<MatcherBa KeyPointVector& _inlier_kps2, DMatchVector& _inlier_matches); + // Check symmetry between nn matches from <im1->im2> and from <im2->im1> pairs + void nnSymmetryTest(const std::vector<DMatchVector>& _matches1, + const std::vector<DMatchVector>& _matches2, + DMatchVector& _sym_matches); + // Factory method static MatcherBasePtr create(const std::string& _unique_name, const ParamsBasePtr _params); -- GitLab