Skip to content

Commit c90cc28

Browse files
author
Fabien Servant
committed
Feature matching chunks
1 parent 2f7b34f commit c90cc28

File tree

9 files changed

+141
-113
lines changed

9 files changed

+141
-113
lines changed

meshroom/aliceVision/FeatureMatching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FeatureMatching(desc.AVCommandLineNode):
88
commandLine = "aliceVision_featureMatching {allParams}"
99
size = avpar.DynamicViewsSize("input")
1010
parallelization = desc.Parallelization(blockSize=20)
11-
commandLineRange = "--rangeStart {rangeStart} --rangeSize {rangeBlockSize}"
11+
commandLineRange = "--rangeIteration {rangeIteration} --rangeBlocksCount {rangeBlocksCount}"
1212

1313
category = "Sparse Reconstruction"
1414
documentation = """

src/aliceVision/matchingImageCollection/ImagePairListIO.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ namespace matchingImageCollection {
1616

1717
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSize, bool useSymmetry)
1818
{
19+
std::ifstream stream(sFileName);
20+
if (!stream.is_open())
21+
{
22+
ALICEVISION_LOG_WARNING("loadPairsFromFile: Impossible to read the specified file: \"" << sFileName << "\".");
23+
return false;
24+
}
25+
1926
std::size_t nbLine = 0;
2027
std::string sValue;
2128

2229
for (; std::getline(stream, sValue); ++nbLine)
2330
{
24-
if (rangeStart != -1 && rangeSize != 0)
25-
{
26-
if (nbLine < rangeStart)
27-
continue;
28-
if (nbLine >= rangeStart + rangeSize)
29-
break;
30-
}
31-
3231
std::vector<std::string> vec_str;
3332
boost::trim(sValue);
3433
boost::split(vec_str, sValue, boost::is_any_of("\t "), boost::token_compress_on);
@@ -39,6 +38,7 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
3938
ALICEVISION_LOG_WARNING("loadPairs: Invalid input file.");
4039
return false;
4140
}
41+
4242
std::stringstream oss;
4343
oss.clear();
4444
oss.str(vec_str[0]);
@@ -71,8 +71,6 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
7171
pairs.insert(pairToInsert);
7272
}
7373
}
74-
return true;
75-
}
7674

7775
void savePairs(std::ostream& stream, const PairSet& pairs)
7876
{
@@ -130,7 +128,29 @@ bool savePairsToFile(const std::string& sFileName, const PairSet& pairs)
130128
return false;
131129
}
132130

133-
savePairs(outStream, pairs);
131+
if (pairs.empty())
132+
{
133+
return false;
134+
}
135+
136+
outStream << pairs.begin()->first << " " << pairs.begin()->second;
137+
IndexT previousIndex = pairs.begin()->first;
138+
139+
// Pairs is sorted so we will always receive elements with the same first pair ID in
140+
// continuous blocks.
141+
for (auto it = std::next(pairs.begin()); it != pairs.end(); ++it)
142+
{
143+
if (it->first == previousIndex)
144+
{
145+
outStream << " " << it->second;
146+
}
147+
else
148+
{
149+
outStream << "\n" << it->first << " " << it->second;
150+
previousIndex = it->first;
151+
}
152+
}
153+
outStream << "\n";
134154

135155
return !outStream.bad();
136156
}

src/aliceVision/matchingImageCollection/ImagePairListIO.hpp

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,60 @@
1313
namespace aliceVision {
1414
namespace matchingImageCollection {
1515

16-
/// Load a set of PairSet from a stream
17-
/// I J K L (pair that link I)
16+
/**
17+
* @brief Load image pairs from an input stream.
18+
*
19+
* Reads image pair data from the provided input stream and populates the pairs set.
20+
* Optionally supports loading a specific range of pairs and symmetry handling.
21+
*
22+
* @param[in] stream Input stream containing the pair data
23+
* @param[out] pairs Set of image pairs to be populated
24+
* @param[in] rangeStart Starting index for loading pairs (default: -1, load all)
25+
* @param[in] rangeSize Number of pairs to load starting from rangeStart (default: 0, load all)
26+
* @param[in] useSymmetry If true, automatically adds symmetric pairs (i,j) and (j,i) (default: true)
27+
* @return true if pairs were successfully loaded, false otherwise
28+
*/
1829
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart = -1, int rangeSize = 0, bool useSymmetry = true);
1930

20-
/// Save a set of PairSet to a stream (one pair per line)
21-
/// I J
22-
/// I K
31+
/**
32+
* @brief Save image pairs to an output stream.
33+
*
34+
* Writes the image pair data to the provided output stream.
35+
*
36+
* @param[out] stream Output stream where pairs will be written
37+
* @param[in] pairs Set of image pairs to save
38+
*/
2339
void savePairs(std::ostream& stream, const PairSet& pairs);
2440

25-
/// Same as loadPairs, but loads from a given file
41+
/**
42+
* @brief Load image pairs from a file.
43+
*
44+
* Reads image pair data from the specified file and populates the pairs set.
45+
* This is a convenience wrapper around loadPairs() that opens the file.
46+
*
47+
* @param[in] sFileName Path to the file containing the pair data
48+
* @param[out] pairs Set of image pairs to be populated
49+
* @param[in] rangeStart Starting index for loading pairs (default: -1, load all)
50+
* @param[in] rangeSize Number of pairs to load starting from rangeStart (default: 0, load all)
51+
* @param[in] useSymmetry If true, automatically adds symmetric pairs (i,j) and (j,i) (default: true)
52+
* @return true if the file was opened and pairs were successfully loaded, false otherwise
53+
*/
2654
bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
2755
PairSet& pairs,
2856
int rangeStart = -1,
2957
int rangeSize = 0,
3058
bool useSymmetry = true);
3159

32-
/// Same as savePairs, but saves to a given file
60+
/**
61+
* @brief Save image pairs to a file.
62+
*
63+
* Writes the image pair data to the specified file.
64+
* This is a convenience wrapper around savePairs() that creates the file.
65+
*
66+
* @param[in] sFileName Path to the output file
67+
* @param[in] pairs Set of image pairs to save
68+
* @return true if the file was created and pairs were successfully saved, false otherwise
69+
*/
3370
bool savePairsToFile(const std::string& sFileName, const PairSet& pairs);
3471

3572
} // namespace matchingImageCollection

src/aliceVision/matchingImageCollection/ImagePairListIO_test.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(read_write_pairs_to_file)
2424

2525
PairSet pairSetGTsorted;
2626
pairSetGTsorted.insert(std::make_pair(0, 1));
27-
pairSetGTsorted.insert(std::make_pair(0, 2));
27+
pairSetGTsorted.insert(std::make_pair(2, 0));
2828
pairSetGTsorted.insert(std::make_pair(1, 2));
2929

3030
BOOST_CHECK(savePairsToFile("pairsT_IO.txt", pairSetGT));
@@ -35,26 +35,3 @@ BOOST_AUTO_TEST_CASE(read_write_pairs_to_file)
3535
std::remove("pairsT_IO.txt");
3636
}
3737

38-
BOOST_AUTO_TEST_CASE(save_pairs)
39-
{
40-
PairSet pairs = {{0, 2}, {0, 4}, {0, 5}, {8, 2}, {0, 1}, {5, 9}};
41-
42-
std::stringstream output;
43-
savePairs(output, pairs);
44-
BOOST_CHECK_EQUAL(output.str(), std::string("0 1 2 4 5\n5 9\n8 2\n"));
45-
}
46-
47-
BOOST_AUTO_TEST_CASE(load_multiple_pairs_per_line)
48-
{
49-
std::stringstream input;
50-
input.str(R"( 0 2 4 5
51-
0 1
52-
5 9
53-
)");
54-
55-
PairSet loadedPairs;
56-
BOOST_CHECK(loadPairs(input, loadedPairs));
57-
58-
PairSet expectedPairs = {{0, 2}, {0, 4}, {0, 5}, {0, 1}, {5, 9}};
59-
BOOST_CHECK(loadedPairs == expectedPairs);
60-
}

src/aliceVision/matchingImageCollection/pairBuilder.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,23 @@
1919
namespace aliceVision {
2020

2121
/// Generate all the (I,J) pairs of the upper diagonal of the NxN matrix
22-
PairSet exhaustivePairs(const sfmData::Views& views, int rangeStart, int rangeSize)
22+
PairSet exhaustivePairs(const std::set<IndexT> & viewIds)
2323
{
2424
PairSet pairs;
25-
sfmData::Views::const_iterator itA = views.begin();
26-
sfmData::Views::const_iterator itAEnd = views.end();
27-
28-
// If we have a rangeStart, only compute the matching for (rangeStart, X).
29-
if (rangeStart != -1 && rangeSize != 0)
30-
{
31-
if (rangeStart >= views.size())
32-
return pairs;
33-
std::advance(itA, rangeStart);
34-
itAEnd = views.begin();
35-
std::advance(itAEnd, std::min(std::size_t(rangeStart + rangeSize), views.size()));
36-
}
25+
auto itA = viewIds.begin();
26+
auto itAEnd = viewIds.end();
3727

3828
for (; itA != itAEnd; ++itA)
3929
{
40-
sfmData::Views::const_iterator itB = itA;
30+
auto itB = itA;
4131
std::advance(itB, 1);
42-
for (; itB != views.end(); ++itB)
43-
pairs.insert(std::make_pair(itA->first, itB->first));
32+
33+
for (; itB != viewIds.end(); ++itB)
34+
{
35+
pairs.insert(std::make_pair(*itA, *itB));
36+
}
4437
}
38+
4539
return pairs;
4640
}
4741

src/aliceVision/matchingImageCollection/pairBuilder.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
namespace aliceVision {
1515

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

1923
}; // namespace aliceVision

src/aliceVision/matchingImageCollection/pairBuilder_test.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,15 @@ bool checkPairOrder(const IterablePairs& pairs)
3434

3535
BOOST_AUTO_TEST_CASE(matchingImageCollection_exhaustivePairs)
3636
{
37-
sfmData::Views views;
3837
{
3938
// Empty
40-
PairSet pairSet = exhaustivePairs(views);
39+
std::set<IndexT> indices;
40+
PairSet pairSet = exhaustivePairs(indices);
4141
BOOST_CHECK_EQUAL(0, pairSet.size());
4242
}
4343
{
44-
std::vector<IndexT> indexes = {{12, 54, 89, 65}};
45-
for (IndexT i : indexes)
46-
{
47-
views.emplace(i, std::make_shared<sfmData::View>("filepath", i));
48-
}
49-
50-
PairSet pairSet = exhaustivePairs(views);
44+
std::set<IndexT> indices = {12, 54, 89, 65};
45+
PairSet pairSet = exhaustivePairs(indices);
5146
BOOST_CHECK(checkPairOrder(pairSet));
5247
BOOST_CHECK_EQUAL(6, pairSet.size());
5348
BOOST_CHECK(pairSet.find(std::make_pair(12, 54)) != pairSet.end());

0 commit comments

Comments
 (0)