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

fix sfm with undistortion #1615

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/aliceVision/sfm/bundle/BundleAdjustmentCeres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ ceres::CostFunction* createCostFunctionFromIntrinsics(const IntrinsicBase* intri
if (undistortion)
{
obsUndistorted.x = undistortion->undistort(observation.x);

if (intrinsicDistortionPtr->getDistortion() != nullptr)
{
throw std::runtime_error("Distortion should not be there when undistortion exists");
}
}
}

Expand All @@ -224,7 +229,7 @@ ceres::CostFunction* createCostFunctionFromIntrinsics(const IntrinsicBase* intri
return new ceres::AutoDiffCostFunction<ResidualErrorFunctor_Pinhole3DEClassicLD, 2, 9, 6, 3>(
new ResidualErrorFunctor_Pinhole3DEClassicLD(w, h, obsUndistorted));
case EINTRINSIC::PINHOLE_CAMERA_3DEANAMORPHIC4:
return new ceres::AutoDiffCostFunction<ResidualErrorFunctor_Pinhole, 2, 18, 6, 3>(new ResidualErrorFunctor_Pinhole(w, h, obsUndistorted));
return new ceres::AutoDiffCostFunction<ResidualErrorFunctor_Pinhole, 2, 4, 6, 3>(new ResidualErrorFunctor_Pinhole(w, h, obsUndistorted));
case EINTRINSIC::PINHOLE_CAMERA_BROWN:
return new ceres::AutoDiffCostFunction<ResidualErrorFunctor_PinholeBrownT2, 2, 9, 6, 3>(
new ResidualErrorFunctor_PinholeBrownT2(w, h, obsUndistorted));
Expand Down
4 changes: 4 additions & 0 deletions src/aliceVision/sfmDataIO/AlembicImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,15 @@ bool readCamera(const Version& abcVersion,
{
distortion->setParameters(distortionParams);
}


std::shared_ptr<camera::Undistortion> undistortion = intrinsicCasted->getUndistortion();
if (undistortion)
{
undistortion->setParameters(undistortionParams);
undistortion->setOffset(undistortionOffset);
//If undistortion exists, distortion does not
intrinsicCasted->setDistortionObject(nullptr);
}
}

Expand Down
35 changes: 19 additions & 16 deletions src/aliceVision/sfmDataIO/jsonIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,6 @@ void loadIntrinsic(const Version& version, IndexT& intrinsicId, std::shared_ptr<

intrinsicWithDistoEnabled->setDistortionInitializationMode(distortionInitializationMode);

std::shared_ptr<camera::Distortion> distortionObject = intrinsicWithDistoEnabled->getDistortion();
if (distortionObject)
{
std::vector<double> distortionParams;
for (bpt::ptree::value_type& paramNode : intrinsicTree.get_child("distortionParams"))
{
distortionParams.emplace_back(paramNode.second.get_value<double>());
}

// ensure that we have the right number of params
if (distortionParams.size() == distortionObject->getParameters().size())
{
distortionObject->setParameters(distortionParams);
}
}

std::shared_ptr<camera::Undistortion> undistortionObject = intrinsicWithDistoEnabled->getUndistortion();
if (undistortionObject)
{
Expand All @@ -375,6 +359,25 @@ void loadIntrinsic(const Version& version, IndexT& intrinsicId, std::shared_ptr<
loadMatrix("undistortionOffset", offset, intrinsicTree);
undistortionObject->setOffset(offset);
}

//If undistortion exists, distortion does not
intrinsicWithDistoEnabled->setDistortionObject(nullptr);
}

std::shared_ptr<camera::Distortion> distortionObject = intrinsicWithDistoEnabled->getDistortion();
if (distortionObject)
{
std::vector<double> distortionParams;
for (bpt::ptree::value_type& paramNode : intrinsicTree.get_child("distortionParams"))
{
distortionParams.emplace_back(paramNode.second.get_value<double>());
}

// ensure that we have the right number of params
if (distortionParams.size() == distortionObject->getParameters().size())
{
distortionObject->setParameters(distortionParams);
}
}
}

Expand Down
Loading