Skip to content

Commit

Permalink
[sfm] Update for ceres2.0 API and shared loss_function openMVG#1715 (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon authored Feb 4, 2023
1 parent efc52a7 commit e5e0349
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/openMVG/sfm/sfm_data_BA_ceres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,18 @@ bool Bundle_Adjustment_Ceres::Adjust
}
}

ceres::Problem problem;
ceres::Problem::Options problem_options;

// Set a LossFunction to be less penalized by false measurements
// - set it to nullptr if you don't want use a lossFunction.
std::unique_ptr<ceres::LossFunction> p_LossFunction;
if (ceres_options_.bUse_loss_function_)
{
p_LossFunction.reset(new ceres::HuberLoss(Square(4.0)));
problem_options.loss_function_ownership = ceres::DO_NOT_TAKE_OWNERSHIP;
}

ceres::Problem problem(problem_options);

// Data wrapper for refinement:
Hash_Map<IndexT, std::vector<double>> map_intrinsics;
Expand Down Expand Up @@ -337,13 +348,6 @@ bool Bundle_Adjustment_Ceres::Adjust
}
}

// Set a LossFunction to be less penalized by false measurements
// - set it to nullptr if you don't want use a lossFunction.
ceres::LossFunction * p_LossFunction =
ceres_options_.bUse_loss_function_ ?
new ceres::HuberLoss(Square(4.0))
: nullptr;

// For all visibility add reprojections errors:
for (auto & structure_landmark_it : sfm_data.structure)
{
Expand All @@ -366,15 +370,15 @@ bool Bundle_Adjustment_Ceres::Adjust
if (!map_intrinsics.at(view->id_intrinsic).empty())
{
problem.AddResidualBlock(cost_function,
p_LossFunction,
p_LossFunction.get(),
&map_intrinsics.at(view->id_intrinsic)[0],
&map_poses.at(view->id_pose)[0],
structure_landmark_it.second.X.data());
}
else
{
problem.AddResidualBlock(cost_function,
p_LossFunction,
p_LossFunction.get(),
&map_poses.at(view->id_pose)[0],
structure_landmark_it.second.X.data());
}
Expand Down

0 comments on commit e5e0349

Please sign in to comment.