Skip to content

Commit

Permalink
Merge branch 'develop' into dev/addAncestorImagesInfoInView
Browse files Browse the repository at this point in the history
  • Loading branch information
cbentejac authored Oct 23, 2023
2 parents 1f104da + 0987a7e commit 0cdfd32
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/aliceVision/camera/Pinhole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ EINTRINSIC Pinhole::getType() const
case EDISTORTION::DISTORTION_FISHEYE1: return EINTRINSIC::PINHOLE_CAMERA_FISHEYE1;
case EDISTORTION::DISTORTION_3DERADIAL4: return EINTRINSIC::PINHOLE_CAMERA_3DERADIAL4;
case EDISTORTION::DISTORTION_3DECLASSICLD: return EINTRINSIC::PINHOLE_CAMERA_3DECLASSICLD;
case EDISTORTION::DISTORTION_3DEANAMORPHIC4: return EINTRINSIC::PINHOLE_CAMERA_3DEANAMORPHIC4;
default: throw std::out_of_range("Invalid distortion model for pinhole camera.");
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/camera/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ inline std::shared_ptr<Distortion> createDistortion(EDISTORTION distortionType,
case EDISTORTION::DISTORTION_3DERADIAL4:
distortion = std::make_shared<Distortion3DERadial4>();
break;
case EDISTORTION::DISTORTION_3DEANAMORPHIC4:
distortion = std::make_shared<Distortion3DEAnamorphic4>();
break;
default: break;
}

Expand Down
1 change: 0 additions & 1 deletion src/aliceVision/keyframe/KeyframeSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ bool KeyframeSelector::writeSelection(const std::vector<std::string>& brands,
oiio::ParamValueList metadata;
metadata.push_back(oiio::ParamValue("Make", brands[id]));
metadata.push_back(oiio::ParamValue("Model", models[id]));
metadata.push_back(oiio::ParamValue("Exif:BodySerialNumber", std::to_string(getRandomInt())));
metadata.push_back(oiio::ParamValue("Exif:FocalLength", mmFocals[id]));
metadata.push_back(oiio::ParamValue("Exif:ImageUniqueID", std::to_string(getRandomInt())));
metadata.push_back(oiio::ParamValue("Orientation", orientation)); // Will not propagate for PNG outputs
Expand Down
50 changes: 37 additions & 13 deletions src/aliceVision/sfm/utils/alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <algorithm>
#include <regex>
#include <numeric>

#include <aliceVision/numeric/gps.hpp>

Expand Down Expand Up @@ -562,6 +563,7 @@ void computeNewCoordinateSystemFromCamerasXAxis(const sfmData::SfMData& sfmData,
meanRy /= validPoses;
meanCameraCenter /= validPoses;

size_t count = 0;
double rms = 0.0;
// Compute covariance matrix of the rotation X component
Eigen::Matrix3d C = Eigen::Matrix3d::Zero();
Expand All @@ -580,34 +582,48 @@ void computeNewCoordinateSystemFromCamerasXAxis(const sfmData::SfMData& sfmData,

const Eigen::Vector3d rX = p.rotation().transpose() * oriented_X;
C += (rX - meanRx) * (rX - meanRx).transpose();

count++;
}
}

if (count > 1)
{
C = C / double(count - 1);
}

Eigen::EigenSolver<Eigen::Matrix3d> solver(C, true);

//Warning, eigenvalues are not sorted ...
Vec3 evalues = solver.eigenvalues().real();
Vec3 aevalues = evalues.cwiseAbs();
IndexT minCol = 0;
double minVal = aevalues[0];
if (aevalues[1] < minVal)
{
minVal = aevalues[1];
minCol = 1;
}
if (aevalues[2] < minVal)
{
minVal = aevalues[2];
minCol = 2;
}

std::vector<int> indices(evalues.size());
std::iota(indices.begin(), indices.end(), 0);
std::sort(indices.begin(), indices.end(), [&](int i, int j) { return evalues[i] < evalues[j]; });
int minCol = indices[0];

//Make sure we have a clear unique small eigen value
double ratio1 = evalues[indices[2]] / evalues[indices[0]];
double ratio2 = evalues[indices[2]] / evalues[indices[1]];
double unicity = ratio1 / ratio2;
double largest = std::abs(evalues[indices[2]]);

ALICEVISION_LOG_DEBUG("computeNewCoordinateSystemFromCamerasXAxis: eigenvalues: " << solver.eigenvalues());
ALICEVISION_LOG_DEBUG("computeNewCoordinateSystemFromCamerasXAxis: eigenvectors: " << solver.eigenvectors());
ALICEVISION_LOG_DEBUG("computeNewCoordinateSystemFromCamerasXAxis: unicity: " << unicity);
ALICEVISION_LOG_DEBUG("computeNewCoordinateSystemFromCamerasXAxis: largest eigen value: " << largest);

// We assume that the X axis of all or majority of the cameras are on a plane.
// The covariance is a flat ellipsoid and the min axis is our candidate Y axis.
Eigen::Vector3d nullestSpace = solver.eigenvectors().col(minCol).real();
const Eigen::Vector3d referenceAxis = Eigen::Vector3d::UnitY();
Eigen::Vector3d referenceAxis = Eigen::Vector3d::UnitY();

if (std::abs(unicity) < 10.0 || largest < 1e-2)
{
ALICEVISION_LOG_DEBUG("Algorithm did not find a clear axis. Align with raw Y.");
nullestSpace = meanRy;
}

// Compute the rotation which rotates nullestSpace onto unitY
out_R = Matrix3d(Quaterniond().setFromTwoVectors(nullestSpace, referenceAxis));
Expand Down Expand Up @@ -655,6 +671,10 @@ void computeNewCoordinateSystemFromCameras(const sfmData::SfMData& sfmData,
stddev += camCenterMean.transpose() * camCenterMean;
}
stddev /= nbCameras;
if (stddev < 1e-12) //If there is no translation change
{
stddev = 1.0;
}

// Make sure the point cloud is centered and scaled to unit deviation
for (Vec3::Index i = 0; i < vCamCenter.cols(); ++i)
Expand Down Expand Up @@ -1108,6 +1128,10 @@ void computeNewCoordinateSystemAuto(const sfmData::SfMData& sfmData, double& out
//By default, scale to get unit rms
const double rms = sqrt(covCamBase.trace() / double(count));
out_S = 1.0 / rms;
if (rms < 1e-12)
{
out_S = 1.0;
}

ALICEVISION_LOG_INFO("Initial point cloud scale: " << rms);

Expand Down
8 changes: 0 additions & 8 deletions src/aliceVision/sfmDataIO/jsonIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,6 @@ void loadIntrinsic(const Version & version, IndexT& intrinsicId, std::shared_ptr
{
distortionObject->setParameters(distortionParams);
}
else
{
intrinsicWithDistoEnabled->setDistortionObject(nullptr);
}
}

std::shared_ptr<camera::Undistortion> undistortionObject = intrinsicWithDistoEnabled->getUndistortion();
Expand All @@ -394,10 +390,6 @@ void loadIntrinsic(const Version & version, IndexT& intrinsicId, std::shared_ptr
loadMatrix("undistortionOffset", offset, intrinsicTree);
undistortionObject->setOffset(offset);
}
else
{
intrinsicWithDistoEnabled->setUndistortionObject(nullptr);
}
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/software/pipeline/main_panoramaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,10 @@ int main(int argc, char* argv[])
const Eigen::AngleAxis<double> Mroll(roll, Eigen::Vector3d::UnitZ());
const Eigen::AngleAxis<double> Mimage(additionalAngle - M_PI_2, Eigen::Vector3d::UnitZ());

const Eigen::Matrix3d cRo = Myaw.toRotationMatrix() * Mpitch.toRotationMatrix() *
const Eigen::Matrix3d oRc = Myaw.toRotationMatrix() * Mpitch.toRotationMatrix() *
Mroll.toRotationMatrix() * Mimage.toRotationMatrix();

rotations[rank] = cRo.transpose();
rotations[rank] = oRc.transpose();
}

if(sfmData.getViews().size() != rotations.size())
Expand All @@ -1041,17 +1041,18 @@ int main(int argc, char* argv[])
}
else if(boost::algorithm::contains(initializeCameras, "horizontal"))
{
constexpr double zenithPitch = -0.5 * boost::math::constants::pi<double>();
constexpr double zenithPitch = 0.5 * boost::math::constants::pi<double>();
const Eigen::AngleAxis<double> zenithMpitch(zenithPitch, Eigen::Vector3d::UnitX());
const Eigen::AngleAxis<double> zenithMroll(additionalAngle, Eigen::Vector3d::UnitZ());
const Eigen::Matrix3d zenithRo = zenithMpitch.toRotationMatrix() * zenithMroll.toRotationMatrix();
const Eigen::Matrix3d oRzenith = zenithMpitch.toRotationMatrix() * zenithMroll.toRotationMatrix();

const bool withZenith = boost::algorithm::contains(initializeCameras, "zenith");
if(initializeCameras == "zenith+horizontal")
{
ALICEVISION_LOG_TRACE("Add zenith first");
rotations[rotations.size()] = zenithRo.transpose();
rotations[rotations.size()] = oRzenith.transpose();
}

const std::size_t nbHorizontalViews = sfmData.getViews().size() - int(withZenith);
for(int x = 0; x < nbHorizontalViews; ++x)
{
Expand All @@ -1066,15 +1067,15 @@ int main(int argc, char* argv[])
const Eigen::AngleAxis<double> Myaw(yaw, Eigen::Vector3d::UnitY());
const Eigen::AngleAxis<double> Mroll(additionalAngle, Eigen::Vector3d::UnitZ());

const Eigen::Matrix3d cRo = Myaw.toRotationMatrix() * Mroll.toRotationMatrix();
const Eigen::Matrix3d oRc = Myaw.toRotationMatrix() * Mroll.toRotationMatrix();

ALICEVISION_LOG_TRACE("Add rotation: yaw=" << yaw);
rotations[rotations.size()] = cRo.transpose();
rotations[rotations.size()] = oRc.transpose();
}
if(initializeCameras == "horizontal+zenith")
{
ALICEVISION_LOG_TRACE("Add zenith");
rotations[rotations.size()] = zenithRo.transpose();
rotations[rotations.size()] = oRzenith.transpose();
}
}
else if(initializeCameras == "spherical" || (initializeCameras.empty() && !nbViewsPerLineString.empty()))
Expand Down Expand Up @@ -1165,12 +1166,12 @@ int main(int argc, char* argv[])
const Eigen::AngleAxis<double> Mpitch(pitch, Eigen::Vector3d::UnitX());
const Eigen::AngleAxis<double> Mroll(roll + additionalAngle, Eigen::Vector3d::UnitZ());

const Eigen::Matrix3d cRo =
const Eigen::Matrix3d oRc =
Myaw.toRotationMatrix() * Mpitch.toRotationMatrix() * Mroll.toRotationMatrix();

ALICEVISION_LOG_TRACE("Add rotation: yaw=" << yaw << ", pitch=" << pitch << ", roll=" << roll
<< ".");
rotations[i++] = cRo.transpose();
rotations[i++] = oRc.transpose();
}
}
}
Expand Down

0 comments on commit 0cdfd32

Please sign in to comment.