Skip to content

Commit

Permalink
[pipeline] Extract removePoorlyOverlappingImagePairs()
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed Oct 17, 2022
1 parent ecbfe1b commit 939dfeb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/aliceVision/matchingImageCollection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(matching_collection_images_files_sources
matchingCommon.cpp
ImageCollectionMatcher_generic.cpp
ImageCollectionMatcher_cascadeHashing.cpp
GeometricFilter.cpp
GeometricFilterMatrix_HGrowing.cpp
geometricFilterUtils.cpp
pairBuilder.cpp
Expand Down
36 changes: 36 additions & 0 deletions src/aliceVision/matchingImageCollection/GeometricFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of the AliceVision project.
// Copyright (c) 2022 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "GeometricFilter.hpp"

namespace aliceVision {
namespace matchingImageCollection {

void removePoorlyOverlappingImagePairs(PairwiseMatches& geometricMatches,
const PairwiseMatches& putativeMatches,
float minimumRatio,
std::size_t minimumGeometricCount)
{
std::vector<PairwiseMatches::key_type> toRemoveVec;
for (const auto& match : geometricMatches)
{
const size_t photometricCount = putativeMatches.find(match.first)->second.getNbAllMatches();
const size_t geometricCount = match.second.getNbAllMatches();
const float ratio = geometricCount / (float)photometricCount;
if (geometricCount < minimumGeometricCount || ratio < minimumRatio) {
toRemoveVec.push_back(match.first); // the image pair will be removed
}
}

// remove discarded pairs
for (const auto& pair : toRemoveVec)
{
geometricMatches.erase(pair);
}
}

} // namespace matchingImageCollection
} // namespace aliceVision
16 changes: 15 additions & 1 deletion src/aliceVision/matchingImageCollection/GeometricFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include <aliceVision/matchingImageCollection/GeometricFilterMatrix.hpp>
#include <aliceVision/system/ProgressDisplay.hpp>

#include <vector>
#include <map>
#include <random>
#include <vector>

namespace aliceVision {
namespace matchingImageCollection {
Expand Down Expand Up @@ -90,6 +91,19 @@ void robustModelEstimation(
}
}

/**
* @brief removePoorlyOverlappingImagePairs Removes image pairs from the given list of geometric
* matches that have poor overlap according to the supplied criteria.
* @param[in,out] geometricMatches List of geometric matches to clean up
* @param putativeMatches List of putative matches
* @param minimumRatio Minimum ratio of geometric to putative matches for image pair
* @param minimumCount Minimum count of geometric matches for image pair
*/
void removePoorlyOverlappingImagePairs(PairwiseMatches& geometricMatches,
const PairwiseMatches& putativeMatches,
float minimumRatio,
std::size_t minimumGeometricCount);

} // namespace matchingImageCollection
} // namespace aliceVision

Expand Down
17 changes: 1 addition & 16 deletions src/software/pipeline/main_featureMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,22 +506,7 @@ int aliceVision_main(int argc, char **argv)
randomNumberGenerator,
guidedMatching);

// perform an additional check to remove pairs with poor overlap
std::vector<PairwiseMatches::key_type> toRemoveVec;
for(PairwiseMatches::const_iterator iterMap = geometricMatches.begin();
iterMap != geometricMatches.end(); ++iterMap)
{
const size_t putativePhotometricCount = mapPutativesMatches.find(iterMap->first)->second.getNbAllMatches();
const size_t putativeGeometricCount = iterMap->second.getNbAllMatches();
const float ratio = putativeGeometricCount / (float)putativePhotometricCount;
if (putativeGeometricCount < 50 || ratio < .3f)
toRemoveVec.push_back(iterMap->first); // the image pair will be removed
}

// remove discarded pairs
for(std::vector<PairwiseMatches::key_type>::const_iterator iter = toRemoveVec.begin();
iter != toRemoveVec.end(); ++iter)
geometricMatches.erase(*iter);
removePoorlyOverlappingImagePairs(geometricMatches, mapPutativesMatches, 0.3f, 50);
}
break;

Expand Down

0 comments on commit 939dfeb

Please sign in to comment.