Skip to content

Commit f05101f

Browse files
authored
Merge pull request #1794 from alicevision/dev/sfmBootstraping
Update sfmBootstraping parameters
2 parents f9eba83 + 11b520b commit f05101f

File tree

4 files changed

+116
-39
lines changed

4 files changed

+116
-39
lines changed

src/aliceVision/sfmData/SfMData.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,27 @@ void SfMData::getBoundingBox(Eigen::Vector3d & bbMin, Eigen::Vector3d & bbMax)
359359
}
360360
}
361361

362+
IndexT SfMData::findView(const std::string & imageName) const
363+
{
364+
IndexT out_viewId = UndefinedIndexT;
365+
366+
// list views uid / filenames and find the one that correspond to the user ones
367+
for (const auto& viewPair : getViews())
368+
{
369+
const auto & v = viewPair.second;
370+
371+
if (imageName == std::to_string(v->getViewId()) ||
372+
imageName == fs::path(v->getImage().getImagePath()).filename().string() ||
373+
imageName == v->getImage().getImagePath())
374+
{
375+
out_viewId = v->getViewId();
376+
break;
377+
}
378+
}
379+
380+
return out_viewId;
381+
}
382+
362383
LandmarksPerView getLandmarksPerViews(const SfMData& sfmData)
363384
{
364385
LandmarksPerView landmarksPerView;

src/aliceVision/sfmData/SfMData.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ class SfMData
376376
*/
377377
View::sptr getViewSharedPtr(IndexT viewId) { return _views.at(viewId); }
378378

379+
/**
380+
* @brief Retrieve the view id in the sfmData from the image filename.
381+
* @param[in] name the image name to find (uid or filename or path)
382+
* @return a view Id if a view is found or UndefinedIndexT
383+
*/
384+
IndexT findView(const std::string & imageName) const;
385+
379386
/**
380387
* @brief Gives the pose of the input view. If this view is part of a rig, it returns rigPose + rigSubPose.
381388
* @param[in] view The given view

src/software/pipeline/main_incrementalSfM.cpp

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,6 @@ namespace fs = std::filesystem;
3838
using namespace aliceVision::track;
3939
using namespace aliceVision::sfm;
4040

41-
/**
42-
* @brief Retrieve the view id in the sfmData from the image filename.
43-
* @param[in] sfmData the SfM scene
44-
* @param[in] name the image name to find (uid or filename or path)
45-
* @param[out] out_viewId the id found
46-
* @return if a view is found
47-
*/
48-
bool retrieveViewIdFromImageName(const sfmData::SfMData& sfmData, const std::string& name, IndexT& out_viewId)
49-
{
50-
out_viewId = UndefinedIndexT;
51-
52-
// list views uid / filenames and find the one that correspond to the user ones
53-
for (const auto& viewPair : sfmData.getViews())
54-
{
55-
const sfmData::View& v = *(viewPair.second.get());
56-
57-
if (name == std::to_string(v.getViewId()) || name == fs::path(v.getImage().getImagePath()).filename().string() ||
58-
name == v.getImage().getImagePath())
59-
{
60-
out_viewId = v.getViewId();
61-
break;
62-
}
63-
}
64-
65-
if (out_viewId == UndefinedIndexT)
66-
ALICEVISION_LOG_ERROR("Can't find the given initial pair view: " << name);
67-
68-
return out_viewId != UndefinedIndexT;
69-
}
7041

7142
int aliceVision_main(int argc, char** argv)
7243
{
@@ -277,7 +248,6 @@ int aliceVision_main(int argc, char** argv)
277248
// return EXIT_FAILURE;
278249
}
279250

280-
// handle initial pair parameter
281251
if (!initialPairString.first.empty() || !initialPairString.second.empty())
282252
{
283253
if (initialPairString.first == initialPairString.second)
@@ -286,20 +256,28 @@ int aliceVision_main(int argc, char** argv)
286256
return EXIT_FAILURE;
287257
}
288258

289-
if (!initialPairString.first.empty() && !retrieveViewIdFromImageName(sfmData, initialPairString.first, sfmParams.userInitialImagePair.first))
259+
if (!initialPairString.first.empty())
290260
{
291-
ALICEVISION_LOG_ERROR("Could not find corresponding view in the initial pair: " + initialPairString.first);
292-
return EXIT_FAILURE;
261+
sfmParams.userInitialImagePair.first = sfmData.findView(initialPairString.first);
262+
if (sfmParams.userInitialImagePair.first == UndefinedIndexT)
263+
{
264+
ALICEVISION_LOG_ERROR("Could not find corresponding view in the initial pair: " + initialPairString.first);
265+
return EXIT_FAILURE;
266+
}
293267
}
294268

295-
if (!initialPairString.second.empty() &&
296-
!retrieveViewIdFromImageName(sfmData, initialPairString.second, sfmParams.userInitialImagePair.second))
269+
if (!initialPairString.second.empty())
297270
{
298-
ALICEVISION_LOG_ERROR("Could not find corresponding view in the initial pair: " + initialPairString.second);
299-
return EXIT_FAILURE;
271+
sfmParams.userInitialImagePair.second = sfmData.findView(initialPairString.second);
272+
if (sfmParams.userInitialImagePair.second == UndefinedIndexT)
273+
{
274+
ALICEVISION_LOG_ERROR("Could not find corresponding view in the initial pair: " + initialPairString.second);
275+
return EXIT_FAILURE;
276+
}
300277
}
301278
}
302279

280+
303281
sfm::ReconstructionEngine_sequentialSfM sfmEngine(sfmData, sfmParams, extraInfoFolder, (fs::path(extraInfoFolder) / "sfm_log.html").string());
304282

305283
sfmEngine.initRandomSeed(randomSeed);

src/software/pipeline/main_sfmBootstraping.cpp

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ int aliceVision_main(int argc, char** argv)
220220

221221
// user optional parameters
222222
const double maxEpipolarDistance = 4.0;
223-
const double minAngle = 5.0;
224-
const double maxAngle = 40.0;
223+
double minAngle = 5.0;
224+
double maxAngle = 40.0;
225+
std::pair<std::string, std::string> initialPairString("", "");
226+
std::pair<IndexT, IndexT> initialPair(UndefinedIndexT, UndefinedIndexT);
225227

226228
int randomSeed = std::mt19937::default_seed;
227229

@@ -232,9 +234,17 @@ int aliceVision_main(int argc, char** argv)
232234
("tracksFilename,t", po::value<std::string>(&tracksFilename)->required(), "Tracks file.")
233235
("pairs,p", po::value<std::string>(&pairsDirectory)->required(), "Path to the pairs directory.");
234236

237+
po::options_description optionalParams("Required parameters");
238+
optionalParams.add_options()
239+
("minAngleInitialPair", po::value<double>(&minAngle)->default_value(minAngle), "Minimum angle for the initial pair.")
240+
("maxAngleInitialPair", po::value<double>(&maxAngle)->default_value(maxAngle), "Maximum angle for the initial pair.")
241+
("initialPairA", po::value<std::string>(&initialPairString.first)->default_value(initialPairString.first), "UID or filepath or filename of the first image.")
242+
("initialPairB", po::value<std::string>(&initialPairString.second)->default_value(initialPairString.second), "UID or filepath or filename of the second image.");
243+
235244
CmdLine cmdline("AliceVision SfM Bootstraping");
236245

237246
cmdline.add(requiredParams);
247+
cmdline.add(optionalParams);
238248
if(!cmdline.execute(argc, argv))
239249
{
240250
return EXIT_FAILURE;
@@ -259,6 +269,45 @@ int aliceVision_main(int argc, char** argv)
259269
return EXIT_SUCCESS;
260270
}
261271

272+
if (!initialPairString.first.empty() || !initialPairString.second.empty())
273+
{
274+
if (initialPairString.first == initialPairString.second)
275+
{
276+
ALICEVISION_LOG_ERROR("Invalid image names. You cannot use the same image to initialize a pair.");
277+
return EXIT_FAILURE;
278+
}
279+
280+
if (!initialPairString.first.empty())
281+
{
282+
initialPair.first = sfmData.findView(initialPairString.first);
283+
if (initialPair.first == UndefinedIndexT)
284+
{
285+
ALICEVISION_LOG_ERROR("Could not find corresponding view in the initial pair: " + initialPairString.first);
286+
return EXIT_FAILURE;
287+
}
288+
}
289+
290+
if (!initialPairString.second.empty())
291+
{
292+
initialPair.second = sfmData.findView(initialPairString.second);
293+
if (initialPair.second == UndefinedIndexT)
294+
{
295+
ALICEVISION_LOG_ERROR("Could not find corresponding view in the initial pair: " + initialPairString.second);
296+
return EXIT_FAILURE;
297+
}
298+
}
299+
}
300+
301+
if (initialPair.first != UndefinedIndexT)
302+
{
303+
ALICEVISION_LOG_INFO("Force one of the selected view to be " << initialPair.first);
304+
}
305+
306+
if (initialPair.second != UndefinedIndexT)
307+
{
308+
ALICEVISION_LOG_INFO("Force one of the selected view to be " << initialPair.second);
309+
}
310+
262311
// Load tracks
263312
ALICEVISION_LOG_INFO("Load tracks");
264313
track::TracksHandler tracksHandler;
@@ -305,11 +354,31 @@ int aliceVision_main(int argc, char** argv)
305354
std::vector<std::size_t> usedTracks;
306355
double angle = 0.0;
307356

357+
if (initialPair.first != UndefinedIndexT)
358+
{
359+
if (pair.reference != initialPair.first && pair.next != initialPair.first)
360+
{
361+
continue;
362+
}
363+
}
364+
365+
if (initialPair.second != UndefinedIndexT)
366+
{
367+
if (pair.reference != initialPair.second && pair.next != initialPair.second)
368+
{
369+
continue;
370+
}
371+
}
372+
373+
ALICEVISION_LOG_INFO("Processing pair " << initialPair.first << " / " << initialPair.second);
374+
308375
if (!estimatePairAngle(sfmData, pair.reference, pair.next, pair.pose, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(), angle, usedTracks))
309376
{
310377
continue;
311378
}
312379

380+
ALICEVISION_LOG_INFO("angle " << initialPair.first << " / " << initialPair.second << " : " << radianToDegree(angle));
381+
313382
if (radianToDegree(angle) > maxAngle)
314383
{
315384
continue;
@@ -330,6 +399,8 @@ int aliceVision_main(int argc, char** argv)
330399
double refScore = sfm::ExpansionPolicyLegacy::computeScore(tracksHandler.getAllTracks(), usedTracks, pair.reference, maxref, 5);
331400
double nextScore = sfm::ExpansionPolicyLegacy::computeScore(tracksHandler.getAllTracks(), usedTracks, pair.next, maxnext, 5);
332401

402+
ALICEVISION_LOG_INFO("image score " << initialPair.first << " / " << initialPair.second << " : " << refScore << " / " << nextScore);
403+
333404
double score = std::min(refScore, nextScore) * std::max(1.0, radianToDegree(angle));
334405

335406

0 commit comments

Comments
 (0)