lsd:optimizationThreadLoop线程

本文详细探讨了lsd中的optimizationThreadLoop线程,揭秘其在程序运行中的关键作用。通过进入optimizationIteration函数,剖析线程如何进行迭代优化,提升系统性能。
摘要由CSDN通过智能技术生成
  while(keepRunning)
  {
    boost::unique_lock<boost::mutex> lock(newConstraintMutex);
    if(!newConstraintAdded)

      //等待新的一致性newConstraintCreatedSignal.timed_wait(lock,boost::posix_time::milliseconds(2000));// slight chance of deadlock otherwise
    newConstraintAdded = false;
    lock.unlock();

    //跑数据集跑完后,做个最终优化
    if(doFinalOptimization)
    {
      printf("doing final optimization iteration!\n");
      optimizationIteration(50, 0.001);
      doFinalOptimization = false;
    }
    //循环优化
    while(optimizationIteration(5, 0.02));
  }

进入optimizationIteration函数:

  // 添加节点和边
  keyFrameGraph->addElementsFromBuffer();
  newConstraintMutex.unlock();

  // Do the optimization. This can take quite some time!优化5次
  int its = keyFrameGraph->optimize(itsPerTry);

  // save the optimization result.
  poseConsistencyMutex.lock_shared();
  keyFrameGraph->keyframesAllMutex.lock_shared();
  float maxChange = 0;
  float sumChange = 0;
  float sum = 0;
  for(size_t i=0;i<keyFrameGraph->keyframesAll.size(); i++)
  {
    // set edge error sum to zero
    keyFrameGraph->keyframesAll[i]->edgeErrorSum = 0;
    keyFrameGraph->keyframesAll[i]->edgesNum = 0;

    if(!keyFrameGraph->keyframesAll[i]->pose->isInGraph) continue;

    // get change from last optimization
    Sim3 a = keyFrameGraph->keyframesAll[i]->pose->graphVertex->estimate();
    Sim3 b = keyFrameGraph->keyframesAll[i]->getScaledCamToWorld();
    Sophus::Vector7f diff = (a*b.inverse()).log().cast<float>();

    for(int j=0;j<7;j++)
    {
      float d = fabsf((float)(diff[j]));
      if(d > maxChange) maxChange = d;
      sumChange += d;
    }
    sum +=7;

    // set change
    keyFrameGraph->keyframesAll[i]->pose->setPoseGraphOptResult(
            keyFrameGraph->keyframesAll[i]->pose->graphVertex->estimate());

    // add error
    for(auto edge : keyFrameGraph->keyframesAll[i]->pose->graphVertex->edges())
    {
      keyFrameGraph->keyframesAll[i]->edgeErrorSum += ((EdgeSim3*)(edge))->chi2();
      keyFrameGraph->keyframesAll[i]->edgesNum++;
    }
  }

  haveUnmergedOptimizationOffset = true;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值