From c4534ef19b3a9b189428b16ae6a6bb169030cbbb Mon Sep 17 00:00:00 2001 From: Joan Sola <jsola@iri.upc.edu> Date: Fri, 4 May 2018 15:41:18 +0200 Subject: [PATCH] FIX: add check of matches vector size when quering with KNN and RADIUS --- src/matchers/matcher_base.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/matchers/matcher_base.cpp b/src/matchers/matcher_base.cpp index 2842d89..8ee93a2 100644 --- a/src/matchers/matcher_base.cpp +++ b/src/matchers/matcher_base.cpp @@ -48,15 +48,13 @@ std::vector<Scalar> MatcherBase::match(const cv::Mat& _desc1, const cv::Mat& _de // This conversion is required when using with hamming descriptors outputs // like BRIEF, ORB, FREAK, AKAZE etc if (_desc1.type()!=CV_32F) - { matcher_ = new cv::FlannBasedMatcher(new cv::flann::LshIndexParams(LSH_TABLE_NUM, LSH_KEY_SIZE, LSH_MULTI_PROBE_LEVEL)); - } matcher_->match( _desc1, _desc2, matches, _mask); // here we get only the best match score for (auto m : matches) - normalized_scores.push_back(1.0 - m.distance/(desc_size_bytes*8)); + normalized_scores.push_back(1.0 - m.distance/(desc_size_bytes*8)); } comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; } @@ -83,7 +81,10 @@ std::vector<Scalar> MatcherBase::match(const cv::Mat& _desc1, const cv::Mat& _de // here we get only the best match score for (auto m : matches) - normalized_scores.push_back(1.0 - m[0].distance/(desc_size_bytes*8)); + if (m.size()>0) + normalized_scores.push_back(1.0 - m[0].distance/(desc_size_bytes*8)); + else + normalized_scores.push_back(0.0); } comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; } @@ -100,7 +101,10 @@ std::vector<Scalar> MatcherBase::match(const cv::Mat& _desc1, const cv::Mat& _de matcher_->radiusMatch(_desc1, _desc2, matches, 2, _mask); for (auto m : matches) - normalized_scores.push_back(1.0 - m[0].distance/(desc_size_bytes*8)); + if (m.size()>0) + normalized_scores.push_back(1.0 - m[0].distance/(desc_size_bytes*8)); + else + normalized_scores.push_back(0.0); } comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; } -- GitLab