Skip to content

Commit

Permalink
[featureMatching] Extract filterMatchesByMin2DMotion()
Browse files Browse the repository at this point in the history
  • Loading branch information
mokibit authored and p12tic committed Oct 8, 2022
1 parent 1607b34 commit 75374e1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 44 deletions.
49 changes: 49 additions & 0 deletions src/aliceVision/matching/matchesFiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/aliceVision/matching/matchesFiltering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <aliceVision/sfmData/SfMData.hpp>
#include <aliceVision/feature/Regions.hpp>
#include <aliceVision/feature/RegionsPerView.hpp>
#include <aliceVision/feature/feature.hpp>
#include <aliceVision/matching/IndMatch.hpp>

Expand Down Expand Up @@ -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
45 changes: 1 addition & 44 deletions src/software/pipeline/main_featureMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down

0 comments on commit 75374e1

Please sign in to comment.