看ORB SLAM代码中遇到的c++知识点

1.system.h中----枚举类型的定义与结构体的定义相似,其形式为:

enum 枚举名{ 
               标识符[=整型常数], 
               标识符[=整型常数], 

... 
               标识符[=整型常数], 

} 枚举变量;

2.string.c_str():

 const * char c_str()
    一个将string转换为 const* char的函数。

    string的c_str()返回的指针是由string管理的。它的生命期是string对象的生命期。然后可以按C的方式使用这个指针,或把它的内容复制出来。

    例如:
        string s;
        cin>>s;
        const char *ch=s.c_str();

   这样就可以从标准输入里输入任意长的字符串,并按const *char来使用。

   如果要把一个char 转换成string, 可以使用 string s(char *);  

3.c++中的类在创建对象时有两种方式:①Text text;②Text* text=new Text();

具体内容参考博客:https://blog.csdn.net/bzhxuexi/article/details/17005287

4.MapSTL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力.

5.pair,make_pair:

这篇博客讲解的特别清楚: https://blog.csdn.net/xywlpo/article/details/6458867

6.STL中的迭代器:

https://blog.csdn.net/huang_xw/article/details/7933244

https://blog.csdn.net/duan19920101/article/details/51679517

两篇结合起来看,哇,醍醐灌顶~

7.size_t:

size_t的引入增强了程序在不同平台上的可移植性。经测试发现,在32位系统中size_t是4字节的,而在64位系统中,size_t是8字节的,这样利用该类型可以增强程序的可移植性。它可以存储任何类型数组的最大大小.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ORBSLAM3是一个视觉SLAM系统,它可以在没有先验地图的情况下从单目、双目和RGB-D相机提取出环境的三维信息。在ORBSLAM3,轨迹对齐是一个重要的步骤,它可以将多个视觉SLAM系统的轨迹对齐到同一个坐标系。以下是ORBSLAM3轨迹对齐的C++代码: ```c++ void Optimizer::BundleAdjustment(const vector<Frame>& vFrames, const vector<MapPoint*>& vpMapPoints, bool* pbStopFlag, const unsigned long nLoopKF, const bool bRobust) { // Create optimization problem ceres::Problem problem; ceres::LossFunction* loss_function = bRobust ? new ceres::HuberLoss(2.0) : NULL; // Add pose blocks for(size_t i=0; i<vFrames.size(); i++) { if(vFrames[i].isBad()) continue; const cv::Mat Rcw = vFrames[i].GetRotation(); const cv::Mat tcw = vFrames[i].GetTranslation(); // Global pose optimization is disabled for the first and second frames if(vFrames[i].mnId != 0 && vFrames[i].mnId != 1) { double angleAxis[3]; ceres::RotationMatrixToAngleAxis((const double*)Rcw.data, angleAxis); problem.AddParameterBlock(angleAxis, 3, new ceres::EigenQuaternionParameterization()); problem.AddParameterBlock((double*)tcw.data, 3); if(i==0) { problem.SetParameterBlockConstant(angleAxis); problem.SetParameterBlockConstant((double*)tcw.data); } else { if(vFrames[i].mnId == nLoopKF) { ceres::LocalParameterization* quaternion_local_parameterization = new ceres::QuaternionParameterization; problem.SetParameterization(angleAxis, quaternion_local_parameterization); } } } } // Add point blocks for(size_t i=0; i<vpMapPoints.size(); i++) { MapPoint* pMP = vpMapPoints[i]; if(pMP==NULL || pMP->isBad()) continue; ceres::CostFunction* cost_function = ReprojectionError::Create(pMP->GetObservationList(), pMP->GetWorldPos()); vector<Frame*> vObservingFrames = pMP->GetObservingFrames(); for(size_t j=0; j<vObservingFrames.size(); j++) { Frame* pFrame = vObservingFrames[j]; if(pFrame->isBad()) continue; ceres::LossFunction* frame_loss_function = vObservingFrames[j]->mnId == nLoopKF ? loss_function : NULL; double angleAxis[3]; ceres::RotationMatrixToAngleAxis((const double*)(pFrame->GetRotation().data), angleAxis); problem.AddResidualBlock(cost_function, frame_loss_function, angleAxis, (double*)(pFrame->GetTranslation().data), pMP->GetWorldPos()); } } // Set solver options ceres::Solver::Options options; options.linear_solver_type = ceres::DENSE_SCHUR; options.max_num_iterations = 40; options.num_threads = 4; options.trust_region_strategy_type = ceres::DOGLEG; options.minimizer_progress_to_stdout = false; options.check_gradients = false; options.gradient_check_relative_precision = 1e-4; options.gradient_check_numeric_derivative_relative_step_size = 1e-5; // Solve the optimization problem ceres::Solver::Summary summary; ceres::Solve(options, &problem, &summary); if(pbStopFlag) if(*pbStopFlag) return; // Update keyframe poses for(size_t i=0; i<vFrames.size(); i++) { if(vFrames[i].isBad()) continue; double angleAxis[3]; if(vFrames[i].mnId != 0 && vFrames[i].mnId != 1) { ceres::AngleAxisToQuaternion((const double*)vFrames[i].GetRotation().data, angleAxis); Eigen::Quaterniond q = Eigen::Map<Eigen::Quaterniond>(angleAxis); cv::Mat Rcw(q.toRotationMatrix()); cv::Mat tcw = cv::Mat(3,1,CV_64F,vFrames[i].GetTranslation().data); vFrames[i].SetPose(Rcw,tcw); } } // Update map points for(size_t i=0; i<vpMapPoints.size(); i++) { MapPoint* pMP = vpMapPoints[i]; if(pMP==NULL || pMP->isBad()) continue; pMP->UpdateNormalAndDepth(); } } ``` 该代码使用Ceres进行优化,将视觉SLAM系统的所有帧和地图点作为优化问题的参数,使用重投影误差作为代价函数,最小化重投影误差,从而优化相机位姿和地图点位置。该代码还包括了一些优化器参数和选项,如线性求解器类型、最大迭代次数、线程数等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值