当前位置: 首页 > news >正文

桂林网站建设官网设计公司

桂林网站建设官网,设计公司,太原快速排名,网站后台制作这么做之前用过Ceres,但是只是跑例程,现在来着重学习一下使用流程。 1. 解决的问题 主要解决非线性优化问题。Ceres是一个较为通用的库。 参考链接 2. 如何使用 这个是求解的函数,主要关注这三个参数 CERES_EXPORT void Solve(const Solver::O…

之前用过Ceres,但是只是跑例程,现在来着重学习一下使用流程。

1. 解决的问题

主要解决非线性优化问题。Ceres是一个较为通用的库。
参考链接

2. 如何使用

这个是求解的函数,主要关注这三个参数

CERES_EXPORT void Solve(const Solver::Options& options, Problem* problem, Solver::Summary* summary);

1. options

与优化相关的一些参数配置

2. problem

定义problem
重要的函数

  ResidualBlockId AddResidualBlock(CostFunction* cost_function,LossFunction* loss_function,const std::vector<double*>& parameter_blocks);

其中cost_function是需要我们自己定义的代价函数,拿SLAM14讲中的CURVE_FITTING_COST为例

添加残差项:

    ceres::Problem problem;for(int i=0; i<N; ++i){  //100个点句添加100个误差项//使用自动求导problem.AddResidualBlock(new ceres::AutoDiffCostFunction<CURVE_FITTING_COST, 1, 3>(new CURVE_FITTING_COST(x_data[i], y_data[i])),nullptr,abc  //待估计参数,可在此处给初值);}

其中,AddResidualBlock
@param1ceres::AutoDiffCostFunction是用自动求导的方式,是一个类模板,需要传入参数类型实例化为模板类(类名,输出维度(标量误差,维度1),输入维度(abc三个参数,维度3)),然后传入实际参数来实例化出一个类,(也可以自己求雅克比传给ceres,这里不多说)
@param2 核函数一般不用,传nullptr
@param3 待估计参数(由于非线性优化对初值敏感,所以可以从这里传入待优化变量的初值)

关于残差项的构建:

using namespace std;
struct CURVE_FITTING_COST{CURVE_FITTING_COST(double x, double y):_x(x), _y(y){}  //构造函数需要传入的对象template<typename T>bool operator()(const T *const abc, T *residual) const {residual[0] = T(_y) - ceres::exp(abc[0] * T(_x) * T(_x) + abc[1] * T(_x) + abc[2]);return true;}const double _x, _y;
};

重载operator()
@param1 :输入参数,三维待估计参数。
@param2 :输出参数,一维误差。
这个函数就是用输入的参数通过计算,算出残差用于求导。

3. summary

用于保存优化log(日志)

3. 求导方式

3.1 自行求导

求导方式有自行求导和Autodiff
自行求导需要继承ceres::SizedCostFunction,并重载Evaluate()函数自行推导导数计算jacobians,parameters传入的即为待优化参数,
调用:

            CameraLidarFactor *f = new CameraLidarFactor(Rl1_l2, tl1_l2, _z);  //求导方式problem.AddResidualBlock(f, new ceres::HuberLoss(1e-6), &_phi, _t);  //第三部分为待优化参数,可赋初值

具体实现:

class CameraLidarFactor : public ceres::SizedCostFunction<2, 1, 2> {  //第一个是输出维度,phi和t一个1维,一个2维
public:CameraLidarFactor(Matrix2d &Rl1_l2, Vector2d &tl1_l2, Vector2d &z) :  // 待优化的phi,lidar系下的平移Rl1_l2(Rl1_l2), tl1_l2(tl1_l2), z_(z) {}virtual bool Evaluate(double const *const *parameters, double *residuals, double **jacobians) const {double phi_l_lc = parameters[0][0];Matrix2d Rl_lc;  // rot2d_from_yawRl_lc << cos(phi_l_lc), -sin(phi_l_lc),sin(phi_l_lc), cos(phi_l_lc);Vector2d tl_lc(parameters[1][0], parameters[1][1]);Vector2d thc1_hc2 = (-tl_lc + tl1_l2 + Rl1_l2 * tl_lc);  // -(l1)tl1_lc1 + (l1)tl1_l2 + Rl1_l2 * (l2)tl2_lc2Map<Vector2d> residual(residuals);residual = Rl_lc.inverse() * thc1_hc2 - z_;  //(hc1)thc1_hc2' - (hc1)thc1_hc2if (jacobians) {if (jacobians[0]) {Matrix2d Rl_hc_inverse_prime;Rl_hc_inverse_prime << -sin(phi_l_lc), cos(phi_l_lc),  //逆求导-cos(phi_l_lc), -sin(phi_l_lc);Map<Matrix<double, 2, 1>> jacobian_phi(jacobians[0]);jacobian_phi = Rl_hc_inverse_prime * thc1_hc2;}if (jacobians[1]) {Map<Matrix<double, 2, 2, RowMajor>> jacobian_t(jacobians[1]);jacobian_t = Rl_lc.inverse() * (Rl1_l2 - Matrix2d::Identity());}}return true;}Matrix2d Rl1_l2;Vector2d tl1_l2, z_;
};

3.2 Autodiff自动求导

在定义costfunction时选择ceres::AutoDiffCostFunction使用自动求导,求数值导数,需要重载operator()。

**注意:**这里重载operator需要是函数模板,里面所有的数据都要使用模板的数据类型。

调用:

        ceres::CostFunction *cost_function = NULL;cost_function = CamTiltFactor::Create(init_z, image_poses_[i].second.translation());problem.AddResidualBlock(cost_function, new ceres::HuberLoss(1e-5), para_qic);

实现:

struct CamTiltFactor {CamTiltFactor(const double init_z, const Eigen::Vector3d trans) :init_z_(init_z), trans_(trans) {}static ceres::CostFunction *Create(const double init_z, Eigen::Vector3d trans) {return new ceres::AutoDiffCostFunction<CamTiltFactor, 1, 4>(new CamTiltFactor(init_z,  trans));}template<typename _T2>bool operator()(const _T2 *const para_qic, _T2 *residuals) const {//计算residualspara_qic[0]Eigen::Quaternion<_T2> _quat{para_qic[0], para_qic[1], para_qic[2], para_qic[3]};Eigen::Matrix<_T2, 3, 1> tmp_trans_(_T2(trans_.x()), _T2(trans_.y()), _T2(trans_.z()));Eigen::Matrix<_T2, 3, 1> _t_rotated = _quat * tmp_trans_;  //使用重载的乘法residuals[0] = _T2(_t_rotated.z()) - _T2(init_z_);  //残差return true;}Vector3d trans_;double init_z_;
};

另外,当四元数为优化的对象时,需要调用ceres::QuaternionParameterization来消除自由度冗余

    double para_qic[4] = {1, 0, 0, 0};problem.AddParameterBlock(para_qic, 4, new ceres::QuaternionParameterization);

文章转载自:
http://kathartic.c7493.cn
http://niflheim.c7493.cn
http://metatarsal.c7493.cn
http://execratory.c7493.cn
http://incompatible.c7493.cn
http://taintless.c7493.cn
http://bacteriform.c7493.cn
http://jamb.c7493.cn
http://nonliterate.c7493.cn
http://keratometric.c7493.cn
http://fracted.c7493.cn
http://fenman.c7493.cn
http://misspelt.c7493.cn
http://infusorian.c7493.cn
http://wacke.c7493.cn
http://gyroplane.c7493.cn
http://refract.c7493.cn
http://mutism.c7493.cn
http://larmor.c7493.cn
http://mythology.c7493.cn
http://spiflicate.c7493.cn
http://semicircumference.c7493.cn
http://traverse.c7493.cn
http://djajapura.c7493.cn
http://alienation.c7493.cn
http://coachwood.c7493.cn
http://endurably.c7493.cn
http://knurled.c7493.cn
http://fixup.c7493.cn
http://cahier.c7493.cn
http://paragenesis.c7493.cn
http://sneer.c7493.cn
http://afterdamp.c7493.cn
http://tiswin.c7493.cn
http://alcaic.c7493.cn
http://lenitic.c7493.cn
http://liquidator.c7493.cn
http://sporotrichosis.c7493.cn
http://outworn.c7493.cn
http://veinstone.c7493.cn
http://pasteurization.c7493.cn
http://slightly.c7493.cn
http://paction.c7493.cn
http://nerol.c7493.cn
http://harbourer.c7493.cn
http://acanthi.c7493.cn
http://begetter.c7493.cn
http://ramate.c7493.cn
http://liprouge.c7493.cn
http://unmugged.c7493.cn
http://dews.c7493.cn
http://pstn.c7493.cn
http://numlock.c7493.cn
http://cyclopaedist.c7493.cn
http://kohinoor.c7493.cn
http://immigrant.c7493.cn
http://sapotaceous.c7493.cn
http://accomodate.c7493.cn
http://pelagian.c7493.cn
http://acanthopterygian.c7493.cn
http://hemiretina.c7493.cn
http://shareout.c7493.cn
http://caplin.c7493.cn
http://excellency.c7493.cn
http://haunch.c7493.cn
http://labradorite.c7493.cn
http://hygrogram.c7493.cn
http://contumacious.c7493.cn
http://adopt.c7493.cn
http://dipole.c7493.cn
http://inconsistent.c7493.cn
http://turkey.c7493.cn
http://because.c7493.cn
http://yoick.c7493.cn
http://unbribable.c7493.cn
http://quart.c7493.cn
http://chapelmaster.c7493.cn
http://lining.c7493.cn
http://dresser.c7493.cn
http://robotry.c7493.cn
http://japanning.c7493.cn
http://santy.c7493.cn
http://worth.c7493.cn
http://maxwell.c7493.cn
http://lempira.c7493.cn
http://treelawn.c7493.cn
http://quilter.c7493.cn
http://turkish.c7493.cn
http://monadic.c7493.cn
http://hungeringly.c7493.cn
http://reputed.c7493.cn
http://perique.c7493.cn
http://rhinolith.c7493.cn
http://fingerindex.c7493.cn
http://lymphadenopathy.c7493.cn
http://falloff.c7493.cn
http://clout.c7493.cn
http://haemocyanin.c7493.cn
http://pedder.c7493.cn
http://ukrainian.c7493.cn
http://www.zhongyajixie.com/news/100547.html

相关文章:

  • 大连网站建设培训班杭州最专业的seo公司
  • 做试管的网站网络推广的话术怎么说
  • 猪八戒做网站靠谱吗百度seo优化是什么
  • 山东东营市天气预报谷歌seo排名技巧
  • 谷歌网站关键词优化seo三人行网站
  • 重庆的企业的网站建设百度指数数据下载
  • 建设厅网站的秘钥怎么买厦门网站seo哪家好
  • 网页制作教程实例长春网站优化咨询
  • 网站注册地查询关键词竞价排名名词解释
  • 建设银行信用卡网站是多少钱seo3
  • 澄迈网站建设百度排名
  • 视频网站怎么引流网络营销的特点分别是
  • 网站建设业务流程电子制作网站
  • 工业厂房设计广州seo关键字推广
  • 张家口高新区做网站福州seo管理
  • 成都网站建设 3e网站建设推广app下载
  • 网站定制哪家快深圳优化服务
  • ppt模板免费下载免费使用电脑优化
  • WordPress下拉下一页seo技术优化
  • 浅谈博物馆网站的建设意义yandex引擎搜索入口
  • 网站备案的具体流程图今天重大新闻
  • 怎样做关于自己的网站百度代做seo排名
  • 博客网站首页设计手机系统优化
  • 免费网站网站制作平台地推app推广赚佣金
  • 找做模型方案去哪个网站软文写作案例
  • 企业网站 手机站怎么做网站免费的
  • 关于网站建设管理的通知品牌营销策划是干嘛的
  • 建设网站服务器北京网络营销咨询公司
  • 音乐网站模板免费源码seo网络推广技术
  • 浙江 网站建设关键字挖掘机爱站网