Skip to content

Commit

Permalink
fix sfm with undistortion
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Dec 5, 2023
1 parent 89d0c26 commit 9b3c886
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/aliceVision/sfm/bundle/BundleAdjustmentCeres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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

0 comments on commit 9b3c886

Please sign in to comment.