Skip to content

Commit

Permalink
[software] incrementalSfM : Add the option minNbMatches
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo committed Jan 28, 2020
1 parent 978a7de commit 326cf4a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/aliceVision/matching/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,23 @@ void filterMatchesByViews(

void filterTopMatches(
PairwiseMatches & allMatches,
const int limitNum)
const int limitNum,
const int minNum)
{
if (limitNum <= 0)
if (limitNum <= 0 && minNum <=0)
return;
if (minNum > limitNum)
throw std::runtime_error("The minimum of matches is higher than the maximum of matches");

for(auto& matchesPerDesc: allMatches)
{
for(auto& matches: matchesPerDesc.second)
{
IndMatches& m = matches.second;
if (m.size() > limitNum)
if (limitNum > 0 && m.size() > limitNum)
m.erase(m.begin()+limitNum, m.end());
if (minNum > 0 && m.size() < minNum)
m.clear();
}
}
}
Expand Down Expand Up @@ -232,7 +237,8 @@ bool Load(
const std::set<IndexT>& viewsKeysFilter,
const std::vector<std::string>& folders,
const std::vector<feature::EImageDescriberType>& descTypesFilter,
const int maxNbMatches)
const int maxNbMatches,
const int minNbMatches)
{
std::size_t nbLoadedMatchFiles = 0;
const std::string pattern = "matches.txt";
Expand Down Expand Up @@ -271,8 +277,7 @@ bool Load(
if(!descTypesFilter.empty())
filterMatchesByDesc(matches, descTypesFilter);

if(maxNbMatches > 0)
filterTopMatches(matches, maxNbMatches);
filterTopMatches(matches, maxNbMatches, minNbMatches);

ALICEVISION_LOG_TRACE("Matches per image pair (after filtering):");
logMatches(matches);
Expand Down
3 changes: 2 additions & 1 deletion src/aliceVision/matching/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ bool Load(PairwiseMatches& matches,
const std::set<IndexT>& viewsKeysFilter,
const std::vector<std::string>& folders,
const std::vector<feature::EImageDescriberType>& descTypesFilter,
const int maxNbMatches = 0);
const int maxNbMatches = 0,
const int minNbMatches =0);

/**
* @brief Filter to keep only specific viewIds.
Expand Down
3 changes: 2 additions & 1 deletion src/aliceVision/sfm/pipeline/pairwiseMatchesIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ inline bool loadPairwiseMatches(
const std::vector<std::string>& folders,
const std::vector<feature::EImageDescriberType>& descTypes,
const int maxNbMatches = 0,
const int minNbMatches = 0,
bool useOnlyMatchesFromFolder = false)
{
std::vector<std::string> matchesFolders;
Expand All @@ -47,7 +48,7 @@ inline bool loadPairwiseMatches(
matchesFolders.insert(matchesFolders.end(), folders.begin(), folders.end());

ALICEVISION_LOG_DEBUG("Loading matches");
if (!matching::Load(out_pairwiseMatches, sfmData.getViewsKeys(), matchesFolders, descTypes, maxNbMatches))
if (!matching::Load(out_pairwiseMatches, sfmData.getViewsKeys(), matchesFolders, descTypes, maxNbMatches, minNbMatches))
{
std::stringstream ss("Unable to read the matches file(s) from:\n");
for(const std::string& folder : matchesFolders)
Expand Down
6 changes: 5 additions & 1 deletion src/software/pipeline/main_incrementalSfM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int main(int argc, char **argv)
sfm::ReconstructionEngine_sequentialSfM::Params sfmParams;
bool lockScenePreviouslyReconstructed = true;
int maxNbMatches = 0;
int minNbMatches = 0;
bool useOnlyMatchesFromInputFolder = false;

po::options_description allParams(
Expand Down Expand Up @@ -118,6 +119,9 @@ int main(int argc, char **argv)
("maxNumberOfMatches", po::value<int>(&maxNbMatches)->default_value(maxNbMatches),
"Maximum number of matches per image pair (and per feature type). "
"This can be useful to have a quick reconstruction overview. 0 means no limit.")
("minNumberOfMatches", po::value<int>(&minNbMatches)->default_value(minNbMatches),
"Minimum number of matches per image pair (and per feature type). "
"This can be useful to have a meaningful reconstruction with accurate keypoints. 0 means no limit.")
("minInputTrackLength", po::value<int>(&sfmParams.minInputTrackLength)->default_value(sfmParams.minInputTrackLength),
"Minimum track length in input of SfM.")
("minAngleForTriangulation", po::value<double>(&sfmParams.minAngleForTriangulation)->default_value(sfmParams.minAngleForTriangulation),
Expand Down Expand Up @@ -242,7 +246,7 @@ int main(int argc, char **argv)

// matches reading
matching::PairwiseMatches pairwiseMatches;
if(!sfm::loadPairwiseMatches(pairwiseMatches, sfmData, matchesFolders, describerTypes, maxNbMatches, useOnlyMatchesFromInputFolder))
if(!sfm::loadPairwiseMatches(pairwiseMatches, sfmData, matchesFolders, describerTypes, maxNbMatches, minNbMatches, useOnlyMatchesFromInputFolder))
{
ALICEVISION_LOG_ERROR("Unable to load matches.");
return EXIT_FAILURE;
Expand Down

0 comments on commit 326cf4a

Please sign in to comment.