Skip to content

Commit

Permalink
Rig support
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Jul 12, 2024
1 parent 8e16a5f commit 56fb14e
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/aliceVision/sfm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(sfm_files_headers
pipeline/expanding/ExpansionHistory.hpp
pipeline/expanding/ExpansionChunk.hpp
pipeline/expanding/ExpansionIteration.hpp
pipeline/expanding/ExpansionPostProcess.hpp
pipeline/expanding/ExpansionPostProcessRig.hpp
pipeline/expanding/ExpansionPolicy.hpp
pipeline/expanding/ExpansionPolicyLegacy.hpp
pipeline/expanding/ExpansionProcess.hpp
Expand Down Expand Up @@ -72,6 +74,7 @@ set(sfm_files_sources
pipeline/expanding/ExpansionChunk.cpp
pipeline/expanding/ExpansionIteration.cpp
pipeline/expanding/ExpansionPolicyLegacy.cpp
pipeline/expanding/ExpansionPostProcessRig.cpp
pipeline/expanding/ExpansionProcess.cpp
pipeline/expanding/ConnexityGraph.cpp
pipeline/expanding/LbaPolicyConnexity.cpp
Expand Down
45 changes: 45 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionPostProcess.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file is part of the AliceVision project.
// Copyright (c) 2024 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include <aliceVision/types.hpp>
#include <aliceVision/sfmData/SfMData.hpp>
#include <aliceVision/track/TracksHandler.hpp>

namespace aliceVision {
namespace sfm {

class ExpansionPostProcess
{
public:
using uptr = std::unique_ptr<ExpansionPostProcess>;

public:

/**
* @brief Perform post process for an iteration
* @param sfmData the scene to process
* @param tracksHandler the tracks for this scene
* @return true if the process succeeded
*/
virtual bool process(sfmData::SfMData & sfmData, track::TracksHandler & tracksHandler) = 0;

/**
* @brief get updated views during process
* @return a set of updated views
*/
const std::set<IndexT> & getUpdatedViews() const
{
return _updatedViews;
}

protected:
std::set<IndexT> _updatedViews;
};

}
}
51 changes: 51 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionPostProcessRig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This file is part of the AliceVision project.
// Copyright (c) 2024 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include <aliceVision/sfm/pipeline/expanding/ExpansionPostProcessRig.hpp>
#include <aliceVision/sfm/pipeline/RigSequence.hpp>

namespace aliceVision {
namespace sfm {

bool ExpansionPostProcessRig::process(sfmData::SfMData & sfmData, track::TracksHandler & tracksHandler)
{
RigParams params;
params.useRigConstraint = true;
params.minNbCamerasForCalibration = _minNumberCameras;
_updatedViews.clear();

if (sfmData.getRigs().empty())
{
return false;
}

/*Calibrate all rigs*/
int countInit = 0;
for (const auto & [rigId, rigObject] : sfmData.getRigs())
{
if (rigObject.isInitialized())
{
continue;
}

RigSequence sequence(sfmData, rigId, params);
sequence.init(tracksHandler.getTracksPerView());
sequence.updateSfM(_updatedViews);

countInit++;
}

if (countInit == 0)
{
return false;
}


return true;
}

}
}
43 changes: 43 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionPostProcessRig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file is part of the AliceVision project.
// Copyright (c) 2024 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include <aliceVision/sfm/pipeline/expanding/ExpansionPostProcess.hpp>

namespace aliceVision {
namespace sfm {

class ExpansionPostProcessRig : public ExpansionPostProcess
{
public:
using uptr = std::unique_ptr<ExpansionPostProcessRig>;

public:

/**
* @brief Perform post process for an iteration
* @param sfmData the scene to process
* @param tracksHandler the tracks for this scene
* @return true if the process succeeded
*/
bool process(sfmData::SfMData & sfmData, track::TracksHandler & tracksHandler) override;

/**
* @brief update the required number of cameras for rig resection
* param count the desired minimal value
*/
void setMinimalNumberCameras(std::size_t count)
{
_minNumberCameras = count;
}

private:
std::size_t _minNumberCameras = 20;
};

}
}
19 changes: 19 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ bool ExpansionProcess::process(sfmData::SfMData & sfmData, track::TracksHandler
{
return false;
}

if (_postProcessHandler)
{
if (_postProcessHandler->process(sfmData, tracksHandler))
{
return true;

if (_iterationHandler->getChunkHandler() == nullptr)
{
return false;
}

// Perform a new estimation step on modified views
if (!_iterationHandler->getChunkHandler()->process(sfmData, tracksHandler, _postProcessHandler->getUpdatedViews()))
{
return false;
}
}
}
}
while (sfmData.getPoses().size() != nbPoses);

Expand Down
16 changes: 16 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/feature/FeaturesPerView.hpp>
#include <aliceVision/sfm/pipeline/expanding/ExpansionIteration.hpp>
#include <aliceVision/sfm/pipeline/expanding/ExpansionHistory.hpp>
#include <aliceVision/sfm/pipeline/expanding/ExpansionPostProcess.hpp>

namespace aliceVision {
namespace sfm {
Expand Down Expand Up @@ -46,6 +47,7 @@ class ExpansionProcess{
{
_historyHandler = expansionHistory;
}

/**
* brief setup the expansion iteration handler
* @param expansionIteration a unique ptr. Ownership will be taken
Expand All @@ -55,6 +57,15 @@ class ExpansionProcess{
_iterationHandler = std::move(expansionIteration);
}

/**
* brief setup the expansion iteration post process handler
* @param expansionPostProcess a unique ptr. Ownership will be taken
*/
void setExpansionIterationPostProcessHandler(ExpansionPostProcess::uptr & expansionPostProcess)
{
_postProcessHandler = std::move(expansionPostProcess);
}

private:

/**
Expand All @@ -81,6 +92,11 @@ class ExpansionProcess{
* Handle iteration prcess
*/
std::unique_ptr<ExpansionIteration> _iterationHandler;

/**
* Postprocess step
*/
ExpansionPostProcess::uptr _postProcessHandler;
};

} // namespace sfm
Expand Down
15 changes: 15 additions & 0 deletions src/software/pipeline/main_sfmExpanding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <aliceVision/sfm/pipeline/expanding/ExpansionIteration.hpp>
#include <aliceVision/sfm/pipeline/expanding/ExpansionProcess.hpp>
#include <aliceVision/sfm/pipeline/expanding/LbaPolicyConnexity.hpp>
#include <aliceVision/sfm/pipeline/expanding/ExpansionPostProcessRig.hpp>

#include <boost/program_options.hpp>

Expand Down Expand Up @@ -51,6 +52,8 @@ int aliceVision_main(int argc, char** argv)
double maxReprojectionError = 4.0;
bool lockAllIntrinsics = false;
int minNbCamerasToRefinePrincipalPoint = 3;
bool useRigConstraint = true;
int minNbCamerasForRigCalibration = 20;

int randomSeed = std::mt19937::default_seed;

Expand Down Expand Up @@ -88,6 +91,8 @@ int aliceVision_main(int argc, char** argv)
"If we do not have enough cameras, the principal point in consider is considered in the center of the image. "
"If minNbCamerasToRefinePrincipalPoint<=0, the principal point is never refined. "
"If minNbCamerasToRefinePrincipalPoint==1, the principal point is always refined.")
("useRigConstraint", po::value<bool>(&useRigConstraint)->default_value(useRigConstraint), "Enable/Disable rig constraint.")
("rigMinNbCamerasForCalibration", po::value<int>(&minNbCamerasForRigCalibration)->default_value(minNbCamerasForRigCalibration),"Minimal number of cameras to start the calibration of the rig.")
;
// clang-format on

Expand Down Expand Up @@ -189,9 +194,19 @@ int aliceVision_main(int argc, char** argv)
expansionIteration->setExpansionPolicyHandler(expansionPolicy);
expansionIteration->setExpansionChunkHandler(expansionChunk);

/*sfm::ExpansionPostProcess::uptr expansionPostProcess;
if (useRigConstraint)
{
sfm::ExpansionPostProcessRig::uptr expansionPostProcessTyped = std::make_unique<sfm::ExpansionPostProcessRig>();
expansionPostProcessTyped->setMinimalNumberCameras(minNbCamerasForRigCalibration);
expansionPostProcess = std::move(expansionPostProcessTyped);
}*/


sfm::ExpansionProcess::uptr expansionProcess = std::make_unique<sfm::ExpansionProcess>();
expansionProcess->setExpansionHistoryHandler(expansionHistory);
expansionProcess->setExpansionIterationHandler(expansionIteration);
/*expansionProcess->setExpansionIterationPostProcessHandler(expansionPostProcess);*/

if (!expansionProcess->process(sfmData, tracksHandler))
{
Expand Down

0 comments on commit 56fb14e

Please sign in to comment.