The following is a general overview of the common implementation for bundle adjustment that adds camera params and tie points (world coordinates) to the problem followed by an adjustment. Now, I am going to add a constraints saying "the average of world coordinates of tie points before and after adjustment should be same". In this context, I should estimate the average of world coordinates of tie points before adjustment and create another cost function to estimate them every iteration and try to keep them as same as the ones before adjustment. Please advise?
for (auto& track : tracks) {
for (const auto& obs : track) {
auto& camera_model =
photos.at(photo_id).camera_model;
std::vector<std::pair<double*, int>> parameters_list;
camera_model.MutableCameraParameters(parameters_list);
auto cost_func = new ceres::AutoDiffCostFunction<ReprojectionError, 2, 12, 3>(new ReprojectionError(obs, camera_model));
std::vector<double*> param_ptrs;
for (const auto& ptr_and_size : parameters_list) {
param_ptrs.emplace_back(ptr_and_size.first);
}
param_ptrs.emplace_back(&track.mutable_world_points()[0]);
problem.AddResidualBlock(cost_func, null_ptr, param_ptrs);
}
}
ceres::Solver::Options options;
Solver::Summary summary;
Solve(options, &problem, &summary);