①在确定好待优化函数后,需要书写一个struct结构来重载 “()” 并且要运用到模板类。
例:
struct Function {
teleplate <typename T>{
operator() (const T* const x, T* residual){
residual[0]=T(10)-x[0];
//待优化函数,例子中为10-x,x为待估计参数,
//真实数据(一般为带噪声的数据)需要用上模板类;带估计参数不用加
return true;
}
}
}
②在构建problem时需要用到这个重载。
CostFunction* cost_function =
new AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor);
problem.AddResidualBlock(cost_function, NULL, &x);
③让我们看一下高翔的SLAM十四讲中关于ceres的代码,注释的十分清晰 。NULL对应的是nullptr核函数 ,abc对应着&x。