Skip to content

Commit

Permalink
filter out bad constraint points
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Jan 17, 2025
1 parent 18da6be commit 47f1a58
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/aliceVision/sfm/pipeline/expanding/SfmBundle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This file is part of the AliceVision project.
// Copyright (c) 2025 AliceVision contributors.
// 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,
Expand Down Expand Up @@ -54,16 +55,20 @@ bool SfmBundle::cleanup(sfmData::SfMData & sfmData)
// Remove landmarks without enough observed parallax
const std::size_t nbOutliersAngleErr = removeOutliersWithAngleError(sfmData, _minAngleForLandmark);

// Remove constraints which are too far away from landmark
const std::size_t nbOutliersConstraints = removeConstraints(sfmData, _maxConstraintDistance);

// Remove poses without enough observations in an interative fashion
const std::size_t nbOutliers = nbOutliersResidualErr + nbOutliersAngleErr;
std::set<IndexT> removedViewsIdIteration;
bool somethingErased = eraseUnstablePosesAndObservations(sfmData, _minPointsPerPose, _minTrackLength, &removedViewsIdIteration);

bool somethingChanged = /*somethingErased || */(nbOutliers > _bundleAdjustmentMaxOutlier);
bool somethingChanged = /*somethingErased || */(nbOutliers > _bundleAdjustmentMaxOutlier) || (nbOutliersConstraints > 0);

ALICEVISION_LOG_INFO("SfmBundle::cleanup : ");
ALICEVISION_LOG_INFO(" - nbOutliersResidualErr : " << nbOutliersResidualErr);
ALICEVISION_LOG_INFO(" - nbOutliersAngleErr : " << nbOutliersAngleErr);
ALICEVISION_LOG_INFO(" - nbOutliersConstraints : " << nbOutliersConstraints);
ALICEVISION_LOG_INFO(" - somethingErased : " << somethingErased);
ALICEVISION_LOG_INFO(" - somethingChanged : " << somethingChanged);

Expand Down
2 changes: 2 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/SfmBundle.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This file is part of the AliceVision project.
// Copyright (c) 2025 AliceVision contributors.
// 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,
Expand Down Expand Up @@ -94,6 +95,7 @@ class SfmBundle
EFeatureConstraint _featureConstraint = EFeatureConstraint::SCALE;
double _maxReprojectionError = 4.0;
double _minAngleForLandmark = 2.0;
double _maxConstraintDistance = 1.0;
size_t _minTrackLength = 2;
size_t _minPointsPerPose = 30;
size_t _bundleAdjustmentMaxOutlier = 50;
Expand Down
41 changes: 41 additions & 0 deletions src/aliceVision/sfm/sfmFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,46 @@ bool eraseUnstablePosesAndObservations(sfmData::SfMData& sfmData,
return removedPoses || removedObservations;
}

IndexT removeConstraints(sfmData::SfMData& sfmData, double maxDist)
{
const auto & landmarks = sfmData.getLandmarks();
auto & constraints = sfmData.getConstraintsPoint();

// Remove all constraints which are very far from associated landmark

size_t count = 0;
auto itConstraints = constraints.begin();
while (itConstraints != constraints.end())
{
IndexT trackId = itConstraints->first;

auto landmarkIt = landmarks.find(trackId);

//If the associated landmark does not exists anymore, remove the constraint
if (landmarkIt == landmarks.end())
{
itConstraints = constraints.erase(itConstraints);
count++;
continue;
}

const Vec3 & lpt = landmarkIt->second.X;
double dist = (itConstraints->second.point - lpt).norm();

//Remove if the landmark is too far away
if (dist > maxDist)
{
itConstraints = constraints.erase(itConstraints);
count++;
}
else
{
++itConstraints;
}
}

return count;
}

} // namespace sfm
} // namespace aliceVision
8 changes: 8 additions & 0 deletions src/aliceVision/sfm/sfmFilters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ IndexT removeOutliersWithPixelResidualError(sfmData::SfMData& sfmData,
// Return the number of removed tracks
IndexT removeOutliersWithAngleError(sfmData::SfMData& sfmData, const double dMinAcceptedAngle);

/**
* @Brief remove all point constraints which are too far away from their associated landmark
* @param sfmData the sfmData to update
* @param maxDist the maximal allowed distance between the landmark and the constraint
* @return the number of constraints removed
*/
IndexT removeConstraints(sfmData::SfMData& sfmData, const double maxDist);

bool eraseUnstablePoses(sfmData::SfMData& sfmData, const IndexT minPointsPerPose, std::set<IndexT>* outRemovedViewsId = NULL);

bool eraseObservationsWithMissingPoses(sfmData::SfMData& sfmData, const IndexT minPointsPerLandmark);
Expand Down

0 comments on commit 47f1a58

Please sign in to comment.