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

[sfmTransform] Rewrite check on ambiguity in sfmTransform #1525

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Changes from all commits
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
13 changes: 7 additions & 6 deletions src/aliceVision/sfm/utils/alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,10 @@ void computeNewCoordinateSystemFromCamerasXAxis(const sfmData::SfMData& sfmData,
//If we use the raw X, it will be in the image without the orientation
//We need to use this orientation to make sure the X spans the horizontal plane.
const Eigen::Vector3d rX = p.rotation().transpose() * oriented_X;
const Eigen::Vector3d rY = p.rotation().transpose() * oriented_Y;

meanRx += rX;
meanRy += oriented_Y;
meanRy += rY;

meanCameraCenter += p.center();
++validPoses;
Expand Down Expand Up @@ -608,18 +609,18 @@ void computeNewCoordinateSystemFromCamerasXAxis(const sfmData::SfMData& sfmData,
Eigen::Vector3d nullestSpace = solver.eigenvectors().col(minCol).real();
const Eigen::Vector3d referenceAxis = Eigen::Vector3d::UnitY();

const double d = nullestSpace.dot(meanRy);
// Compute the rotation which rotates nullestSpace onto unitY
out_R = Matrix3d(Quaterniond().setFromTwoVectors(nullestSpace, referenceAxis));
const double d = (out_R * meanRy).normalized().dot(Eigen::Vector3d::UnitY());
const bool inverseDirection = (d < 0.0);
// We have an ambiguity on the Y direction, so if our Y axis is not aligned with the Y axis of the scene
// we inverse the axis.
if(inverseDirection)
{
nullestSpace = -nullestSpace;
out_R = Matrix3d(Quaterniond().setFromTwoVectors(nullestSpace, referenceAxis));
}


// Compute the rotation which rotates nullestSpace onto unitY
out_R = Matrix3d(Quaterniond().setFromTwoVectors(nullestSpace, referenceAxis));

out_S = 1.0;
out_t = -out_R * meanCameraCenter;
}
Expand Down