Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meshroom/aliceVision/FeatureMatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FeatureMatching(desc.AVCommandLineNode):
commandLine = "aliceVision_featureMatching {allParams}"
size = desc.DynamicNodeSize("input")
parallelization = desc.Parallelization(blockSize=20)
commandLineRange = "--rangeStart {rangeStart} --rangeSize {rangeBlockSize}"
commandLineRange = "--rangeIteration {rangeIteration} --rangeBlocksCount {rangeBlocksCount}"

category = "Sparse Reconstruction"
documentation = """
Expand Down
87 changes: 27 additions & 60 deletions src/aliceVision/matchingImageCollection/ImagePairListIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
namespace aliceVision {
namespace matchingImageCollection {

bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSize)

bool loadPairsFromFile(const std::string& sFileName, PairSet& pairs)
{
std::ifstream stream(sFileName);
if (!stream.is_open())
{
ALICEVISION_LOG_WARNING("loadPairsFromFile: Impossible to read the specified file: \"" << sFileName << "\".");
return false;
}

std::size_t nbLine = 0;
std::string sValue;

for (; std::getline(stream, sValue); ++nbLine)
{
if (rangeStart != -1 && rangeSize != 0)
{
if (nbLine < rangeStart)
continue;
if (nbLine >= rangeStart + rangeSize)
break;
}

std::vector<std::string> vec_str;
boost::trim(sValue);
boost::split(vec_str, sValue, boost::is_any_of("\t "), boost::token_compress_on);
Expand All @@ -39,6 +39,7 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
ALICEVISION_LOG_WARNING("loadPairs: Invalid input file.");
return false;
}

std::stringstream oss;
oss.clear();
oss.str(vec_str[0]);
Expand All @@ -49,32 +50,30 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
oss.clear();
oss.str(vec_str[i]);
oss >> J;
if (I == J)
{
ALICEVISION_LOG_WARNING("loadPairs: Invalid input file. Image " << I << " sees itself.");
return false;
}
Pair pairToInsert = (I < J) ? std::make_pair(I, J) : std::make_pair(J, I);
if (pairs.find(pairToInsert) != pairs.end())
{
// There is no reason to have the same image pair twice in the list of image pairs
// to match.
ALICEVISION_LOG_WARNING("loadPairs: image pair (" << I << ", " << J << ") already added.");
}
ALICEVISION_LOG_INFO("loadPairs: image pair (" << I << ", " << J << ") added.");

Pair pairToInsert = std::make_pair(I, J);
pairs.insert(pairToInsert);
}
}

return true;
}

void savePairs(std::ostream& stream, const PairSet& pairs)
bool savePairsToFile(const std::string& sFileName, const PairSet& pairs)
{
std::ofstream outStream(sFileName);
if (!outStream.is_open())
{
ALICEVISION_LOG_WARNING("savePairsToFile: Impossible to open the output specified file: \"" << sFileName << "\".");
return false;
}

if (pairs.empty())
{
return;
return false;
}
stream << pairs.begin()->first << " " << pairs.begin()->second;

outStream << pairs.begin()->first << " " << pairs.begin()->second;
IndexT previousIndex = pairs.begin()->first;

// Pairs is sorted so we will always receive elements with the same first pair ID in
Expand All @@ -83,47 +82,15 @@ void savePairs(std::ostream& stream, const PairSet& pairs)
{
if (it->first == previousIndex)
{
stream << " " << it->second;
outStream << " " << it->second;
}
else
{
stream << "\n" << it->first << " " << it->second;
outStream << "\n" << it->first << " " << it->second;
previousIndex = it->first;
}
}
stream << "\n";
}

bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
PairSet& pairs,
int rangeStart,
int rangeSize)
{
std::ifstream in(sFileName);
if (!in.is_open())
{
ALICEVISION_LOG_WARNING("loadPairsFromFile: Impossible to read the specified file: \"" << sFileName << "\".");
return false;
}

if (!loadPairs(in, pairs, rangeStart, rangeSize))
{
ALICEVISION_LOG_WARNING("loadPairsFromFile: Failed to read file: \"" << sFileName << "\".");
return false;
}
return true;
}

bool savePairsToFile(const std::string& sFileName, const PairSet& pairs)
{
std::ofstream outStream(sFileName);
if (!outStream.is_open())
{
ALICEVISION_LOG_WARNING("savePairsToFile: Impossible to open the output specified file: \"" << sFileName << "\".");
return false;
}

savePairs(outStream, pairs);
outStream << "\n";

return !outStream.bad();
}
Expand Down
32 changes: 16 additions & 16 deletions src/aliceVision/matchingImageCollection/ImagePairListIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
namespace aliceVision {
namespace matchingImageCollection {

/// Load a set of PairSet from a stream
/// I J K L (pair that link I)
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart = -1, int rangeSize = 0);

/// Save a set of PairSet to a stream (one pair per line)
/// I J
/// I K
void savePairs(std::ostream& stream, const PairSet& pairs);

/// Same as loadPairs, but loads from a given file
bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
PairSet& pairs,
int rangeStart = -1,
int rangeSize = 0);

/// Same as savePairs, but saves to a given file
/**
* @Brief load pairs from file
* File format is reference matchImg1 matchImage2 ...\n
* @param sFileName input file path to load
* @param pairs the output set of pairs
* @return false if a problem is detected in the file
*/
bool loadPairsFromFile(const std::string& sFileName, PairSet& pairs);

/**
* @Brief Save pairs to file
* File format is reference matchImg1 matchImage2 ...\n
* @param sFileName input file path to save
* @param pairs the input set of pairs
* @return false if a problem is detected in the file
*/
bool savePairsToFile(const std::string& sFileName, const PairSet& pairs);

} // namespace matchingImageCollection
Expand Down
25 changes: 1 addition & 24 deletions src/aliceVision/matchingImageCollection/ImagePairListIO_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(read_write_pairs_to_file)

PairSet pairSetGTsorted;
pairSetGTsorted.insert(std::make_pair(0, 1));
pairSetGTsorted.insert(std::make_pair(0, 2));
pairSetGTsorted.insert(std::make_pair(2, 0));
pairSetGTsorted.insert(std::make_pair(1, 2));

BOOST_CHECK(savePairsToFile("pairsT_IO.txt", pairSetGT));
Expand All @@ -35,26 +35,3 @@ BOOST_AUTO_TEST_CASE(read_write_pairs_to_file)
std::remove("pairsT_IO.txt");
}

BOOST_AUTO_TEST_CASE(save_pairs)
{
PairSet pairs = {{0, 2}, {0, 4}, {0, 5}, {8, 2}, {0, 1}, {5, 9}};

std::stringstream output;
savePairs(output, pairs);
BOOST_CHECK_EQUAL(output.str(), std::string("0 1 2 4 5\n5 9\n8 2\n"));
}

BOOST_AUTO_TEST_CASE(load_multiple_pairs_per_line)
{
std::stringstream input;
input.str(R"( 0 2 4 5
0 1
5 9
)");

PairSet loadedPairs;
BOOST_CHECK(loadPairs(input, loadedPairs));

PairSet expectedPairs = {{0, 2}, {0, 4}, {0, 5}, {0, 1}, {5, 9}};
BOOST_CHECK(loadedPairs == expectedPairs);
}
26 changes: 10 additions & 16 deletions src/aliceVision/matchingImageCollection/pairBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,23 @@
namespace aliceVision {

/// Generate all the (I,J) pairs of the upper diagonal of the NxN matrix
PairSet exhaustivePairs(const sfmData::Views& views, int rangeStart, int rangeSize)
PairSet exhaustivePairs(const std::set<IndexT> & viewIds)
{
PairSet pairs;
sfmData::Views::const_iterator itA = views.begin();
sfmData::Views::const_iterator itAEnd = views.end();

// If we have a rangeStart, only compute the matching for (rangeStart, X).
if (rangeStart != -1 && rangeSize != 0)
{
if (rangeStart >= views.size())
return pairs;
std::advance(itA, rangeStart);
itAEnd = views.begin();
std::advance(itAEnd, std::min(std::size_t(rangeStart + rangeSize), views.size()));
}
auto itA = viewIds.begin();
auto itAEnd = viewIds.end();

for (; itA != itAEnd; ++itA)
{
sfmData::Views::const_iterator itB = itA;
auto itB = itA;
std::advance(itB, 1);
for (; itB != views.end(); ++itB)
pairs.insert(std::make_pair(itA->first, itB->first));

for (; itB != viewIds.end(); ++itB)
{
pairs.insert(std::make_pair(*itA, *itB));
}
}

return pairs;
}

Expand Down
8 changes: 6 additions & 2 deletions src/aliceVision/matchingImageCollection/pairBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

namespace aliceVision {

/// Generate all the (I,J) pairs of the upper diagonal of the NxN matrix
PairSet exhaustivePairs(const sfmData::Views& views, int rangeStart = -1, int rangeSize = 0);
/**
* @brief Generate all the (I,J) pairs of the upper diagonal of the NxN matrix
* @param views the sfmData views indices list
* @return a generated set of pairs
*/
PairSet exhaustivePairs(const std::set<IndexT> & viewIds);

}; // namespace aliceVision
13 changes: 4 additions & 9 deletions src/aliceVision/matchingImageCollection/pairBuilder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,15 @@ bool checkPairOrder(const IterablePairs& pairs)

BOOST_AUTO_TEST_CASE(matchingImageCollection_exhaustivePairs)
{
sfmData::Views views;
{
// Empty
PairSet pairSet = exhaustivePairs(views);
std::set<IndexT> indices;
PairSet pairSet = exhaustivePairs(indices);
BOOST_CHECK_EQUAL(0, pairSet.size());
}
{
std::vector<IndexT> indexes = {{12, 54, 89, 65}};
for (IndexT i : indexes)
{
views.emplace(i, std::make_shared<sfmData::View>("filepath", i));
}

PairSet pairSet = exhaustivePairs(views);
std::set<IndexT> indices = {12, 54, 89, 65};
PairSet pairSet = exhaustivePairs(indices);
BOOST_CHECK(checkPairOrder(pairSet));
BOOST_CHECK_EQUAL(6, pairSet.size());
BOOST_CHECK(pairSet.find(std::make_pair(12, 54)) != pairSet.end());
Expand Down
Loading
Loading