Skip to content

Commit aab762a

Browse files
author
Fabien Servant
committed
Feature matching chunks
1 parent ce485af commit aab762a

File tree

9 files changed

+122
-171
lines changed

9 files changed

+122
-171
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 = desc.DynamicNodeSize("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: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
namespace aliceVision {
1515
namespace matchingImageCollection {
1616

17-
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSize)
17+
18+
bool loadPairsFromFile(const std::string& sFileName, PairSet& pairs)
1819
{
20+
std::ifstream stream(sFileName);
21+
if (!stream.is_open())
22+
{
23+
ALICEVISION_LOG_WARNING("loadPairsFromFile: Impossible to read the specified file: \"" << sFileName << "\".");
24+
return false;
25+
}
26+
1927
std::size_t nbLine = 0;
2028
std::string sValue;
2129

2230
for (; std::getline(stream, sValue); ++nbLine)
2331
{
24-
if (rangeStart != -1 && rangeSize != 0)
25-
{
26-
if (nbLine < rangeStart)
27-
continue;
28-
if (nbLine >= rangeStart + rangeSize)
29-
break;
30-
}
31-
3232
std::vector<std::string> vec_str;
3333
boost::trim(sValue);
3434
boost::split(vec_str, sValue, boost::is_any_of("\t "), boost::token_compress_on);
@@ -39,6 +39,7 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
3939
ALICEVISION_LOG_WARNING("loadPairs: Invalid input file.");
4040
return false;
4141
}
42+
4243
std::stringstream oss;
4344
oss.clear();
4445
oss.str(vec_str[0]);
@@ -49,32 +50,30 @@ bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart, int rangeSi
4950
oss.clear();
5051
oss.str(vec_str[i]);
5152
oss >> J;
52-
if (I == J)
53-
{
54-
ALICEVISION_LOG_WARNING("loadPairs: Invalid input file. Image " << I << " sees itself.");
55-
return false;
56-
}
57-
Pair pairToInsert = (I < J) ? std::make_pair(I, J) : std::make_pair(J, I);
58-
if (pairs.find(pairToInsert) != pairs.end())
59-
{
60-
// There is no reason to have the same image pair twice in the list of image pairs
61-
// to match.
62-
ALICEVISION_LOG_WARNING("loadPairs: image pair (" << I << ", " << J << ") already added.");
63-
}
64-
ALICEVISION_LOG_INFO("loadPairs: image pair (" << I << ", " << J << ") added.");
53+
54+
Pair pairToInsert = std::make_pair(I, J);
6555
pairs.insert(pairToInsert);
6656
}
6757
}
58+
6859
return true;
6960
}
7061

71-
void savePairs(std::ostream& stream, const PairSet& pairs)
62+
bool savePairsToFile(const std::string& sFileName, const PairSet& pairs)
7263
{
64+
std::ofstream outStream(sFileName);
65+
if (!outStream.is_open())
66+
{
67+
ALICEVISION_LOG_WARNING("savePairsToFile: Impossible to open the output specified file: \"" << sFileName << "\".");
68+
return false;
69+
}
70+
7371
if (pairs.empty())
7472
{
75-
return;
73+
return false;
7674
}
77-
stream << pairs.begin()->first << " " << pairs.begin()->second;
75+
76+
outStream << pairs.begin()->first << " " << pairs.begin()->second;
7877
IndexT previousIndex = pairs.begin()->first;
7978

8079
// Pairs is sorted so we will always receive elements with the same first pair ID in
@@ -83,47 +82,15 @@ void savePairs(std::ostream& stream, const PairSet& pairs)
8382
{
8483
if (it->first == previousIndex)
8584
{
86-
stream << " " << it->second;
85+
outStream << " " << it->second;
8786
}
8887
else
8988
{
90-
stream << "\n" << it->first << " " << it->second;
89+
outStream << "\n" << it->first << " " << it->second;
9190
previousIndex = it->first;
9291
}
9392
}
94-
stream << "\n";
95-
}
96-
97-
bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
98-
PairSet& pairs,
99-
int rangeStart,
100-
int rangeSize)
101-
{
102-
std::ifstream in(sFileName);
103-
if (!in.is_open())
104-
{
105-
ALICEVISION_LOG_WARNING("loadPairsFromFile: Impossible to read the specified file: \"" << sFileName << "\".");
106-
return false;
107-
}
108-
109-
if (!loadPairs(in, pairs, rangeStart, rangeSize))
110-
{
111-
ALICEVISION_LOG_WARNING("loadPairsFromFile: Failed to read file: \"" << sFileName << "\".");
112-
return false;
113-
}
114-
return true;
115-
}
116-
117-
bool savePairsToFile(const std::string& sFileName, const PairSet& pairs)
118-
{
119-
std::ofstream outStream(sFileName);
120-
if (!outStream.is_open())
121-
{
122-
ALICEVISION_LOG_WARNING("savePairsToFile: Impossible to open the output specified file: \"" << sFileName << "\".");
123-
return false;
124-
}
125-
126-
savePairs(outStream, pairs);
93+
outStream << "\n";
12794

12895
return !outStream.bad();
12996
}

src/aliceVision/matchingImageCollection/ImagePairListIO.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
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)
18-
bool loadPairs(std::istream& stream, PairSet& pairs, int rangeStart = -1, int rangeSize = 0);
19-
20-
/// Save a set of PairSet to a stream (one pair per line)
21-
/// I J
22-
/// I K
23-
void savePairs(std::ostream& stream, const PairSet& pairs);
24-
25-
/// Same as loadPairs, but loads from a given file
26-
bool loadPairsFromFile(const std::string& sFileName, // filename of the list file,
27-
PairSet& pairs,
28-
int rangeStart = -1,
29-
int rangeSize = 0);
30-
31-
/// Same as savePairs, but saves to a given file
16+
/**
17+
* @Brief load pairs from file
18+
* File format is reference matchImg1 matchImage2 ...\n
19+
* @param sFileName input file path to load
20+
* @param pairs the output set of pairs
21+
* @return false if a problem is detected in the file
22+
*/
23+
bool loadPairsFromFile(const std::string& sFileName, PairSet& pairs);
24+
25+
/**
26+
* @Brief Save pairs to file
27+
* File format is reference matchImg1 matchImage2 ...\n
28+
* @param sFileName input file path to save
29+
* @param pairs the input set of pairs
30+
* @return false if a problem is detected in the file
31+
*/
3232
bool savePairsToFile(const std::string& sFileName, const PairSet& pairs);
3333

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