Skip to content

Commit d3b8005

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

File tree

9 files changed

+142
-118
lines changed

9 files changed

+142
-118
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: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@
1414
namespace aliceVision {
1515
namespace matchingImageCollection {
1616

17-
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSize, bool useSymmetry)
17+
bool loadPairs(std::istream& stream, PairSet& pairs, bool useSymmetry)
1818
{
1919
std::size_t nbLine = 0;
2020
std::string sValue;
2121

2222
for (; std::getline(stream, sValue); ++nbLine)
2323
{
24-
if (rangeStart != -1 && rangeSize != 0)
25-
{
26-
if (nbLine < rangeStart)
27-
continue;
28-
if (nbLine >= rangeStart + rangeSize)
29-
break;
30-
}
31-
3224
std::vector<std::string> vec_str;
3325
boost::trim(sValue);
3426
boost::split(vec_str, sValue, boost::is_any_of("\t "), boost::token_compress_on);
@@ -39,6 +31,7 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
3931
ALICEVISION_LOG_WARNING("loadPairs: Invalid input file.");
4032
return false;
4133
}
34+
4235
std::stringstream oss;
4336
oss.clear();
4437
oss.str(vec_str[0]);
@@ -102,8 +95,6 @@ void savePairs(std::ostream& stream, const PairSet& pairs)
10295

10396
bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
10497
PairSet& pairs,
105-
int rangeStart,
106-
int rangeSize,
10798
bool useSymmetry)
10899
{
109100
std::ifstream in(sFileName);
@@ -113,7 +104,7 @@ bool loadPairsFromFile(const std::string& sFileName, // filename of the list fi
113104
return false;
114105
}
115106

116-
if (!loadPairs(in, pairs, rangeStart, rangeSize, useSymmetry))
107+
if (!loadPairs(in, pairs, useSymmetry))
117108
{
118109
ALICEVISION_LOG_WARNING("loadPairsFromFile: Failed to read file: \"" << sFileName << "\".");
119110
return false;
@@ -130,7 +121,29 @@ bool savePairsToFile(const std::string& sFileName, const PairSet& pairs)
130121
return false;
131122
}
132123

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

135148
return !outStream.bad();
136149
}

src/aliceVision/matchingImageCollection/ImagePairListIO.hpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
// v. 2.0. If a copy of the MPL was not distributed with this file,
66
// You can obtain one at https://mozilla.org/MPL/2.0/.
77

8+
/**
9+
* @file ImagePairListIO.hpp
10+
* @brief Input/Output functions for reading and writing image pair lists.
11+
*
12+
* This file provides utilities for loading and saving sets of image pairs
13+
* to and from streams and files. Image pairs are used in the matching process
14+
* to define which images should be compared for feature matching.
15+
*/
16+
817
#include <aliceVision/types.hpp>
918

1019
#include <iosfwd>
@@ -13,23 +22,54 @@
1322
namespace aliceVision {
1423
namespace matchingImageCollection {
1524

16-
/// Load a set of PairSet from a stream
17-
/// I J K L (pair that link I)
18-
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart = -1, int rangeSize = 0, bool useSymmetry = true);
25+
/**
26+
* @brief Load image pairs from an input stream.
27+
*
28+
* Reads image pair data from the provided input stream and populates the pairs set.
29+
* Optionally supports symmetry handling.
30+
*
31+
* @param[in] stream Input stream containing the pair data
32+
* @param[out] pairs Set of image pairs to be populated
33+
* @param[in] useSymmetry If true, automatically adds symmetric pairs (i,j) and (j,i) (default: true)
34+
* @return true if pairs were successfully loaded, false otherwise
35+
*/
36+
bool loadPairs(std::istream& stream, PairSet& pairs, bool useSymmetry = true);
1937

20-
/// Save a set of PairSet to a stream (one pair per line)
21-
/// I J
22-
/// I K
38+
/**
39+
* @brief Save image pairs to an output stream.
40+
*
41+
* Writes the image pair data to the provided output stream.
42+
*
43+
* @param[out] stream Output stream where pairs will be written
44+
* @param[in] pairs Set of image pairs to save
45+
*/
2346
void savePairs(std::ostream& stream, const PairSet& pairs);
2447

25-
/// Same as loadPairs, but loads from a given file
48+
/**
49+
* @brief Load image pairs from a file.
50+
*
51+
* Reads image pair data from the specified file and populates the pairs set.
52+
* This is a convenience wrapper around loadPairs() that opens the file.
53+
*
54+
* @param[in] sFileName Path to the file containing the pair data
55+
* @param[out] pairs Set of image pairs to be populated
56+
* @param[in] useSymmetry If true, automatically adds symmetric pairs (i,j) and (j,i) (default: true)
57+
* @return true if the file was opened and pairs were successfully loaded, false otherwise
58+
*/
2659
bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
2760
PairSet& pairs,
28-
int rangeStart = -1,
29-
int rangeSize = 0,
3061
bool useSymmetry = true);
3162

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

3575
} // 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)