diff --git a/src/aliceVision/matching/matchesFiltering.cpp b/src/aliceVision/matching/matchesFiltering.cpp index f550002668..87d643f5fc 100644 --- a/src/aliceVision/matching/matchesFiltering.cpp +++ b/src/aliceVision/matching/matchesFiltering.cpp @@ -139,6 +139,60 @@ void matchesGridFiltering(const aliceVision::feature::Regions& lRegions, outMatches.swap(finalMatches); } +void matchesGridFilteringForAllPairs(const PairwiseMatches& geometricMatches, + const sfmData::SfMData& sfmData, + const feature::RegionsPerView& regionPerView, + bool useGridSort, + std::size_t numMatchesToKeep, + PairwiseMatches& outPairwiseMatches) +{ + for (const auto& geometricMatch: geometricMatches) + { + //Get the image pair and their matches. + const Pair& indexImagePair = geometricMatch.first; + const MatchesPerDescType& matchesPerDesc = geometricMatch.second; + + for (const auto& match: matchesPerDesc) + { + const feature::EImageDescriberType descType = match.first; + assert(descType != feature::EImageDescriberType::UNINITIALIZED); + const IndMatches& inputMatches = match.second; + + const feature::Regions* rRegions = ®ionPerView.getRegions(indexImagePair.second, descType); + const feature::Regions* lRegions = ®ionPerView.getRegions(indexImagePair.first, descType); + + // get the regions for the current view pair: + if(rRegions && lRegions) + { + // sorting function: + aliceVision::matching::IndMatches outMatches; + sortMatches_byFeaturesScale(inputMatches, *lRegions, *rRegions, outMatches); + + if(useGridSort) + { + // TODO: rename as matchesGridOrdering + matchesGridFiltering(*lRegions, sfmData.getView(indexImagePair.first).getImgSize(), + *rRegions, sfmData.getView(indexImagePair.second).getImgSize(), + indexImagePair, outMatches); + } + + if (numMatchesToKeep > 0) + { + size_t finalSize = std::min(numMatchesToKeep, outMatches.size()); + outMatches.resize(finalSize); + } + + // std::cout << "Left features: " << lRegions->Features().size() << ", right features: " << rRegions->Features().size() << ", num matches: " << inputMatches.size() << ", num filtered matches: " << outMatches.size() << std::endl; + outPairwiseMatches[indexImagePair].insert(std::make_pair(descType, outMatches)); + } + else + { + ALICEVISION_LOG_INFO("You cannot perform the grid filtering with these regions"); + } + } + } +} + void filterMatchesByMin2DMotion(PairwiseMatches& mapPutativesMatches, const feature::RegionsPerView& regionPerView, double minRequired2DMotion) diff --git a/src/aliceVision/matching/matchesFiltering.hpp b/src/aliceVision/matching/matchesFiltering.hpp index 2898167bc9..3d9671f07f 100644 --- a/src/aliceVision/matching/matchesFiltering.hpp +++ b/src/aliceVision/matching/matchesFiltering.hpp @@ -67,6 +67,13 @@ void matchesGridFiltering(const aliceVision::feature::Regions& lRegions, const aliceVision::Pair& indexImagePair, aliceVision::matching::IndMatches& outMatches, size_t gridSize = 3); +void matchesGridFilteringForAllPairs(const PairwiseMatches& geometricMatches, + const sfmData::SfMData& sfmData, + const feature::RegionsPerView& regionPerView, + bool useGridSort, std::size_t numMatchesToKeep, + PairwiseMatches& outPairwiseMatches); + + void filterMatchesByMin2DMotion(PairwiseMatches& mapPutativesMatches, const feature::RegionsPerView& regionPerView, double minRequired2DMotion); diff --git a/src/software/pipeline/main_featureMatching.cpp b/src/software/pipeline/main_featureMatching.cpp index ff97d32acd..b68013d5ff 100644 --- a/src/software/pipeline/main_featureMatching.cpp +++ b/src/software/pipeline/main_featureMatching.cpp @@ -558,57 +558,17 @@ int aliceVision_main(int argc, char **argv) ALICEVISION_LOG_INFO("Grid filtering"); PairwiseMatches finalMatches; - - { - for(const auto& geometricMatch: geometricMatches) - { - //Get the image pair and their matches. - const Pair& indexImagePair = geometricMatch.first; - const aliceVision::matching::MatchesPerDescType& matchesPerDesc = geometricMatch.second; - - for(const auto& match: matchesPerDesc) - { - const feature::EImageDescriberType descType = match.first; - assert(descType != feature::EImageDescriberType::UNINITIALIZED); - const aliceVision::matching::IndMatches& inputMatches = match.second; - - const feature::Regions* rRegions = ®ionPerView.getRegions(indexImagePair.second, descType); - const feature::Regions* lRegions = ®ionPerView.getRegions(indexImagePair.first, descType); - - // get the regions for the current view pair: - if(rRegions && lRegions) - { - // sorting function: - aliceVision::matching::IndMatches outMatches; - sortMatches_byFeaturesScale(inputMatches, *lRegions, *rRegions, outMatches); - - if(useGridSort) - { - // TODO: rename as matchesGridOrdering - matchesGridFiltering(*lRegions, sfmData.getView(indexImagePair.first).getImgSize(), - *rRegions, sfmData.getView(indexImagePair.second).getImgSize(), - indexImagePair, outMatches); - } - if(numMatchesToKeep > 0) - { - size_t finalSize = std::min(numMatchesToKeep, outMatches.size()); - outMatches.resize(finalSize); - } - - // std::cout << "Left features: " << lRegions->Features().size() << ", right features: " << rRegions->Features().size() << ", num matches: " << inputMatches.size() << ", num filtered matches: " << outMatches.size() << std::endl; - finalMatches[indexImagePair].insert(std::make_pair(descType, outMatches)); - } - else - { - ALICEVISION_LOG_INFO("You cannot perform the grid filtering with these regions"); - } - } - } + matchesGridFilteringForAllPairs(geometricMatches, sfmData, regionPerView, useGridSort, + numMatchesToKeep, finalMatches); ALICEVISION_LOG_INFO("After grid filtering:"); - for(const auto& matchGridFiltering: finalMatches) - ALICEVISION_LOG_INFO("\t- image pair (" + std::to_string(matchGridFiltering.first.first) + ", " + std::to_string(matchGridFiltering.first.second) + ") contains " + std::to_string(matchGridFiltering.second.getNbAllMatches()) + " geometric matches."); - } + for (const auto& matchGridFiltering: finalMatches) + { + ALICEVISION_LOG_INFO("\t- image pair (" << matchGridFiltering.first.first << ", " + << matchGridFiltering.first.second << ") contains " + << matchGridFiltering.second.getNbAllMatches() + << " geometric matches."); + } // export geometric filtered matches ALICEVISION_LOG_INFO("Save geometric matches.");