Skip to content

Commit

Permalink
Merge pull request #810 from alicevision/matching/fixUnimplemented
Browse files Browse the repository at this point in the history
[Matching] fix unmatching declaration and definitions
  • Loading branch information
fabiencastan authored Jun 16, 2020
2 parents 4590ae8 + 402a41a commit 4d13542
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 80 deletions.
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Contributing Workflow
The contributing workflow relies on [Github Pull Requests](https://help.github.com/articles/using-pull-requests/).

1. If it is an important change, we recommend you to discuss it on the mailing-list
before starting implementation. This ensure that the development is aligned with other
developpements already started and will be efficiently integrated.
before starting implementation. This ensure that the development is aligned with other developments already started and will be efficiently integrated.

2. Create the corresponding issues.

Expand Down
63 changes: 24 additions & 39 deletions src/aliceVision/matching/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ bool LoadMatchFile(PairwiseMatches& matches, const std::string& filepath)
return false;
}


void filterMatchesByViews(
PairwiseMatches & matches,
const std::set<IndexT> & viewsKeys)
void filterMatchesByViews(PairwiseMatches& matches, const std::set<IndexT>& viewsKeys)
{
matching::PairwiseMatches filteredMatches;
for (matching::PairwiseMatches::const_iterator iter = matches.begin();
Expand All @@ -97,14 +94,11 @@ void filterMatchesByViews(
matches.swap(filteredMatches);
}

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

for(auto& matchesPerDesc: allMatches)
Expand All @@ -114,15 +108,13 @@ void filterTopMatches(
IndMatches& m = matches.second;
if (minNum > 0 && m.size() < minNum)
m.clear();
else if (limitNum > 0 && m.size() > limitNum)
m.erase(m.begin()+limitNum, m.end());
else if (maxNum > 0 && m.size() > maxNum)
m.erase(m.begin()+ maxNum, m.end());
}
}
}

void filterMatchesByDesc(
PairwiseMatches & allMatches,
const std::vector<feature::EImageDescriberType>& descTypesFilter)
void filterMatchesByDesc(PairwiseMatches& allMatches, const std::vector<feature::EImageDescriberType>& descTypesFilter)
{
matching::PairwiseMatches filteredMatches;
for(const auto& matchesPerDesc: allMatches)
Expand All @@ -138,12 +130,10 @@ void filterMatchesByDesc(
allMatches.swap(filteredMatches);
}


std::size_t LoadMatchFilePerImage(
PairwiseMatches& matches,
const std::set<IndexT>& viewsKeys,
const std::string& folder,
const std::string& basename)
std::size_t LoadMatchFilePerImage(PairwiseMatches& matches,
const std::set<IndexT>& viewsKeys,
const std::string& folder,
const std::string& extension)
{
int nbLoadedMatchFiles = 0;
// Load one match file per image
Expand All @@ -153,7 +143,7 @@ std::size_t LoadMatchFilePerImage(
std::set<IndexT>::const_iterator it = viewsKeys.begin();
std::advance(it, i);
const IndexT idView = *it;
const std::string matchFilename = std::to_string(idView) + "." + basename;
const std::string matchFilename = std::to_string(idView) + "." + extension;
PairwiseMatches fileMatches;
if(!LoadMatchFile(fileMatches, (fs::path(folder) / matchFilename).string() ))
{
Expand Down Expand Up @@ -232,13 +222,12 @@ std::size_t loadMatchesFromFolder(PairwiseMatches& matches, const std::string& f
return nbLoadedMatchFiles;
}

bool Load(
PairwiseMatches& matches,
const std::set<IndexT>& viewsKeysFilter,
const std::vector<std::string>& folders,
const std::vector<feature::EImageDescriberType>& descTypesFilter,
const int maxNbMatches,
const int minNbMatches)
bool Load(PairwiseMatches& matches,
const std::set<IndexT>& viewsKeysFilter,
const std::vector<std::string>& folders,
const std::vector<feature::EImageDescriberType>& descTypesFilter,
int maxNbMatches,
int minNbMatches)
{
std::size_t nbLoadedMatchFiles = 0;
const std::string pattern = "matches.txt";
Expand Down Expand Up @@ -332,8 +321,7 @@ class MatchExporter
, m_ext(fs::extension(filename))
{}

~MatchExporter()
{}
~MatchExporter() = default;

void saveGlobalFile()
{
Expand Down Expand Up @@ -380,14 +368,11 @@ class MatchExporter
std::string m_filename;
};


bool Save(
const PairwiseMatches & matches,
const std::string & folder,
const std::string & extension,
bool matchFilePerImage,
const std::string& prefix
)
bool Save(const PairwiseMatches& matches,
const std::string& folder,
const std::string& extension,
bool matchFilePerImage,
const std::string& prefix)
{
const std::string filename = prefix + "matches." + extension;
MatchExporter exporter(matches, folder, filename);
Expand Down
81 changes: 42 additions & 39 deletions src/aliceVision/matching/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,76 +14,79 @@
namespace aliceVision {
namespace matching {


/**
* @brief Load a match file.
*
* @param[out] matches: container for the output matches
* @param[in] folder: folder containing the match files
* @param[out] matches container for the output matches
* @param[in] filepath the match file to load
*/
bool LoadMatchFile(
PairwiseMatches& matches,
const std::string& folder,
const std::string& filename);
bool LoadMatchFile(PairwiseMatches& matches, const std::string& filepath);

/**
* @brief Load the match file for each image.
*
* @param[out] matches: container for the output matches
* @param[in] folder: folder containing the match files
* @param[out] matches container for the output matches.
* @param[in] viewsKeys the list of views whose match files need to be loaded.
* @param[in] folder the folder where to look for all the files.
* @param[in] extension the extension of the match file.
* @return the number of match file actually loaded (if a file cannot be loaded it is discarded)
*/
bool LoadMatchFilePerImage(
PairwiseMatches& matches,
const std::set<IndexT>& viewsKeys,
const std::string& folder);
std::size_t LoadMatchFilePerImage(PairwiseMatches& matches,
const std::set<IndexT>& viewsKeys,
const std::string& folder,
const std::string& extension);

/**
* @brief Load match files.
* @brief Load all the matches from the folder. Optionally filter the view, the type of descriptors
* and the number of matches.
*
* @param[out] matches: container for the output matches
* @param[in] sfm_data
* @param[in] folder: folder containing the match files
* @param[in] descTypes
* @param[in] maxNbMatches: to load the N first matches for each desc. type. Load all the matches by default (: 0)
* @param[out] matches container for the output matches.
* @param[in] viewsKeysFilter Restrict the matches to these views.
* @param[in] folders The list of folder from where to lead the match files.
* @param[in] descTypesFilter Restrict the matches to these types of descriptors.
* @param[in] maxNbMatches keep at most \p maxNbMatches matches (0 takes all matches).
* @param[in] minNbMatches discard the match files with less than \p minNbMatches (0 takes all files).
* @return \p false if no file could be loaded.
* @see filterMatchesByViews
* @see filterTopMatches
*/
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 minNbMatches =0);
const std::set<IndexT>& viewsKeysFilter,
const std::vector<std::string>& folders,
const std::vector<feature::EImageDescriberType>& descTypesFilter,
int maxNbMatches = 0,
int minNbMatches = 0);

/**
* @brief Filter to keep only specific viewIds.
* @param[in,out] matches the matches to filter.
* @param[in] viewsKeys the list of views to keep.
*/
void filterMatchesByViews(
PairwiseMatches& matches,
const std::set<IndexT>& viewsKeys);
void filterMatchesByViews(PairwiseMatches& matches, const std::set<IndexT>& viewsKeys);

/**
* @brief Filter to keep only the \c limitNum first matches per descriptor type.
* @brief Filter to keep only the \c limitNum first matches per descriptor type.
* @param[in,out] allMatches he matches to filter.
* @param[in] maxNum The maximum number of matches to retrieve.
* @param[in] minNum The minimum number of matches that the file must contain (otherwise it is discarded).
*/
void filterTopMatches(
PairwiseMatches& allMatches,
const int limitNum);
void filterTopMatches(PairwiseMatches& allMatches, int maxNum, int minNum);

/**
* @brief Save match files.
*
* @param[in] matches: container for the output matches
* @param[in] sfm_data
* @param[in] folder: folder containing the match files
* @param[in] extension: txt or bin file format
* @param[in] matchFilePerImage: do we store a global match file
* or one match file per image
* @param[in] prefix: optional prefix for the output file(s)
*/
bool Save(
const PairwiseMatches& matches,
const std::string& folder,
const std::string& extension,
bool matchFilePerImage,
const std::string& prefix="");
bool Save(const PairwiseMatches& matches,
const std::string& folder,
const std::string& extension,
bool matchFilePerImage,
const std::string& prefix = "");

} // namespace matching
} // namespace aliceVision

0 comments on commit 4d13542

Please sign in to comment.