From 75374e108145c889c99c2e8061643a71b6a63032 Mon Sep 17 00:00:00 2001 From: Monika Kairaityte Date: Mon, 8 Aug 2022 13:59:47 +0300 Subject: [PATCH] [featureMatching] Extract filterMatchesByMin2DMotion() --- src/aliceVision/matching/matchesFiltering.cpp | 49 +++++++++++++++++++ src/aliceVision/matching/matchesFiltering.hpp | 5 ++ .../pipeline/main_featureMatching.cpp | 45 +---------------- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/aliceVision/matching/matchesFiltering.cpp b/src/aliceVision/matching/matchesFiltering.cpp index cb1d17aeed..f550002668 100644 --- a/src/aliceVision/matching/matchesFiltering.cpp +++ b/src/aliceVision/matching/matchesFiltering.cpp @@ -139,5 +139,54 @@ void matchesGridFiltering(const aliceVision::feature::Regions& lRegions, outMatches.swap(finalMatches); } +void filterMatchesByMin2DMotion(PairwiseMatches& mapPutativesMatches, + const feature::RegionsPerView& regionPerView, + double minRequired2DMotion) +{ + if (minRequired2DMotion < 0.0f) + return; + + //For each image pair + for (auto& imgPair: mapPutativesMatches) + { + const Pair viewPair = imgPair.first; + IndexT viewI = viewPair.first; + IndexT viewJ = viewPair.second; + + //For each descriptors in this image + for (auto& descType: imgPair.second) + { + const feature::EImageDescriberType type = descType.first; + + const feature::Regions & regions_I = regionPerView.getRegions(viewI, type); + const feature::Regions & regions_J = regionPerView.getRegions(viewJ, type); + + const auto & features_I = regions_I.Features(); + const auto & features_J = regions_J.Features(); + + IndMatches & matches = descType.second; + IndMatches updated_matches; + + for (auto & match : matches) + { + Vec2f pi = features_I[match._i].coords(); + Vec2f pj = features_J[match._j].coords(); + + float scale = std::max(features_I[match._i].scale(), features_J[match._j].scale()); + float coeff = pow(2, scale); + + if ((pi - pj).norm() < (minRequired2DMotion * coeff)) + { + continue; + } + + updated_matches.push_back(match); + } + + matches = updated_matches; + } + } +} + } // namespace sfm } // namespace aliceVision diff --git a/src/aliceVision/matching/matchesFiltering.hpp b/src/aliceVision/matching/matchesFiltering.hpp index 9c9e593fba..2898167bc9 100644 --- a/src/aliceVision/matching/matchesFiltering.hpp +++ b/src/aliceVision/matching/matchesFiltering.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -66,5 +67,9 @@ void matchesGridFiltering(const aliceVision::feature::Regions& lRegions, const aliceVision::Pair& indexImagePair, aliceVision::matching::IndMatches& outMatches, size_t gridSize = 3); +void filterMatchesByMin2DMotion(PairwiseMatches& mapPutativesMatches, + const feature::RegionsPerView& regionPerView, + double minRequired2DMotion); + } // namespace sfm } // namespace aliceVision diff --git a/src/software/pipeline/main_featureMatching.cpp b/src/software/pipeline/main_featureMatching.cpp index 375f513079..ff97d32acd 100644 --- a/src/software/pipeline/main_featureMatching.cpp +++ b/src/software/pipeline/main_featureMatching.cpp @@ -383,50 +383,7 @@ int aliceVision_main(int argc, char **argv) } - if (minRequired2DMotion >= 0.0f) - { - //For each image pair - for (auto& imgPair: mapPutativesMatches) - { - const Pair viewPair = imgPair.first; - IndexT viewI = viewPair.first; - IndexT viewJ = viewPair.second; - - //For each descriptors in this image - for (auto& descType: imgPair.second) - { - const feature::EImageDescriberType type = descType.first; - - const feature::Regions & regions_I = regionPerView.getRegions(viewI, type); - const feature::Regions & regions_J = regionPerView.getRegions(viewJ, type); - - const auto & features_I = regions_I.Features(); - const auto & features_J = regions_J.Features(); - - IndMatches & matches = descType.second; - IndMatches updated_matches; - - for (auto & match : matches) - { - - Vec2f pi = features_I[match._i].coords(); - Vec2f pj = features_J[match._j].coords(); - - float scale = std::max(features_I[match._i].scale(), features_J[match._j].scale()); - float coeff = pow(2, scale); - - if ((pi - pj).norm() < (minRequired2DMotion * coeff)) - { - continue; - } - - updated_matches.push_back(match); - } - - matches = updated_matches; - } - } - } + filterMatchesByMin2DMotion(mapPutativesMatches, regionPerView, minRequired2DMotion); if(mapPutativesMatches.empty()) {