Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sfm] make sure we give other chances to candidates #1200

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ bool ReconstructionEngine_sequentialSfM::process()
// The optimization could allow the triangulation of new landmarks
triangulate({}, prevReconstructedViews);
bundleAdjustment(prevReconstructedViews);

registerChanges(prevReconstructedViews);
}

// reconstruction
Expand Down Expand Up @@ -325,12 +327,57 @@ void ReconstructionEngine_sequentialSfM::createInitialReconstruction(const std::
{
// successfully found an initial image pair
ALICEVISION_LOG_INFO("Initial pair is: " << initialPairCandidate.first << ", " << initialPairCandidate.second);

std::set<IndexT> updatedViews;
updatedViews.insert(initialPairCandidate.first);
updatedViews.insert(initialPairCandidate.second);
registerChanges(updatedViews);

return;
}
}
throw std::runtime_error("Initialization failed after trying all possible initial image pairs.");
}

void ReconstructionEngine_sequentialSfM::registerChanges(const std::set<IndexT>& newReconstructedViews)
{
_registeredCandidatesViews.clear();

const sfmData::Landmarks & landmarks = _sfmData.getLandmarks();
for (IndexT id : newReconstructedViews)
{
const track::TrackIdSet & setTracks = _map_tracksPerView[id];

for (auto idTrack : setTracks)
{
//Check that this track is indeed a landmark
if (landmarks.find(idTrack) == landmarks.end())
{
continue;
}

//Check that this view is a registered observation of this landmark (confirmed track)
const Landmark & l = landmarks.at(idTrack);
if (l.observations.find(id) == l.observations.end())
{
continue;
}

const track::Track & track = _map_tracks[idTrack];
for (const auto & pairFeat : track.featPerView)
{
IndexT oview = pairFeat.first;
if (oview == id)
{
continue;
}

_registeredCandidatesViews.insert(oview);
}
}
}
}

void ReconstructionEngine_sequentialSfM::remapLandmarkIdsToTrackIds()
{
using namespace track;
Expand Down Expand Up @@ -393,6 +440,7 @@ double ReconstructionEngine_sequentialSfM::incrementalReconstruction()
IndexT resectionId = 0;

std::set<IndexT> remainingViewIds;
std::set<IndexT> candidateViewIds;
std::vector<IndexT> bestViewCandidates;

// get all viewIds and max resection id
Expand All @@ -401,11 +449,14 @@ double ReconstructionEngine_sequentialSfM::incrementalReconstruction()
IndexT viewId = viewPair.second->getViewId();
IndexT viewResectionId = viewPair.second->getResectionId();

//Create a list of remaining views to estimate
if(!_sfmData.isPoseAndIntrinsicDefined(viewId))
{
remainingViewIds.insert(viewId);
}

if(viewResectionId != UndefinedIndexT &&
viewResectionId > resectionId)
//Make sure we can use the higher resectionIds
if(viewResectionId != UndefinedIndexT && viewResectionId > resectionId)
{
resectionId = viewResectionId + 1;
}
Expand All @@ -432,20 +483,25 @@ double ReconstructionEngine_sequentialSfM::incrementalReconstruction()
}

aliceVision::system::Timer timer;

std::size_t nbValidPoses = 0;
std::size_t globalIteration = 0;

do
{
//Compute intersection of available views and views with potential changes
candidateViewIds.clear();
std::set_intersection(remainingViewIds.begin(), remainingViewIds.end(), _registeredCandidatesViews.begin(), _registeredCandidatesViews.end(), std::inserter(candidateViewIds, candidateViewIds.end()));

nbValidPoses = _sfmData.getPoses().size();
ALICEVISION_LOG_INFO("Incremental Reconstruction start iteration " << globalIteration << ":" << std::endl
<< "\t- # number of resection groups: " << resectionId << std::endl
<< "\t- # number of poses: " << nbValidPoses << std::endl
<< "\t- # number of landmarks: " << _sfmData.structure.size() << std::endl
<< "\t- # remaining images: " << remainingViewIds.size()
);

// compute robust resection of remaining images
while(findNextBestViews(bestViewCandidates, remainingViewIds))
while (findNextBestViews(bestViewCandidates, candidateViewIds))
{
ALICEVISION_LOG_INFO("Update Reconstruction:" << std::endl
<< "\t- resection id: " << resectionId << std::endl
Expand All @@ -455,14 +511,31 @@ double ReconstructionEngine_sequentialSfM::incrementalReconstruction()
// get reconstructed views before resection
const std::set<IndexT> prevReconstructedViews = _sfmData.getValidViews();

std::set<IndexT> newReconstructedViews = resection(resectionId, bestViewCandidates, prevReconstructedViews, remainingViewIds);

std::set<IndexT> newReconstructedViews = resection(resectionId, bestViewCandidates, prevReconstructedViews, candidateViewIds);
if(newReconstructedViews.empty())
{
candidateViewIds.clear();
continue;
}


triangulate(prevReconstructedViews, newReconstructedViews);
bundleAdjustment(newReconstructedViews);


//Erase reconstructed views from list of available views
for (auto v : newReconstructedViews)
{
remainingViewIds.erase(v);
}

//Compute the connected views to inform we have new information !
registerChanges(newReconstructedViews);

//Compute intersection of available views and views with potential changes
candidateViewIds.clear();
std::set_intersection(remainingViewIds.begin(), remainingViewIds.end(), _registeredCandidatesViews.begin(), _registeredCandidatesViews.end(), std::inserter(candidateViewIds, candidateViewIds.end()));

// scene logging for visual debug
if((resectionId % 3) == 0)
{
Expand Down Expand Up @@ -580,7 +653,6 @@ double ReconstructionEngine_sequentialSfM::incrementalReconstruction()
{
ALICEVISION_LOG_DEBUG("Resection of image " << i << " ( view id: " << viewId << " ) was not possible.");
}
remainingViewIds.erase(viewId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ class ReconstructionEngine_sequentialSfM : public ReconstructionEngine
const std::set<IndexT>& newReconstructedViews,
std::map<IndexT, std::set<IndexT> > & mapTracksToTriangulate) const;

/**
* @brief Loop over the reconstructed views, and for each landmarks of the reconstructed views,
fabiencastan marked this conversation as resolved.
Show resolved Hide resolved
* loop over their tracks to detect which views may have new information using this newly reconstructed views
*
* @param newReconstructedViews a list of reconstructed views to analyse
*/
void registerChanges(const std::set<IndexT>& newReconstructedViews);

/**
* @brief Remove observation/tracks that have:
* - too large residual error
Expand All @@ -355,6 +363,9 @@ class ReconstructionEngine_sequentialSfM : public ReconstructionEngine
std::vector<int> _pyramidWeights;
int _pyramidThreshold;

//List of views which are affected by a previous update
std::set<IndexT> _registeredCandidatesViews;

// Temporary data

fabiencastan marked this conversation as resolved.
Show resolved Hide resolved
/// Putative landmark tracks (visibility per potential 3D point)
Expand Down