RGBD-SLAM (学习笔记)

参考高博士的blog:https://www.cnblogs.com/gaoxiang12/tag/%E4%B8%80%E8%B5%B7%E5%81%9ARGB-D%20SLAM/

RGBD-SLAM (3)

Feature Detector, Descriptor and Matcher

  • 第一个问题就是找不到detector, 发现问题在于openCV的extra modules没有装, 必须自己从source来build, 包括openCV和openCV contrib的modules

  • 第二个问题是没有设置nonfree-option
    Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SIFT::create'
    参考:https://www.kancloud.cn/kingchao/wqc666/1099275

  • 第三个问题就是图片改名字了,不存在

  • Debug的一个笔误: 问题现象是match永远是0,说明是在对同一个图像进行处理,问题代码如下 (自行观察)

    detector->detectAndCompute(rgb1, cv::noArray(), kp1, desp1);
    detector->detectAndCompute(rgb1, cv::noArray(), kp2, desp2);
  • 求解PnP,在openCV3中有一点与openCV2不同,即参数confidence由0100改为01,因此改为:
    cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 0.99 , inliers );

RGBD-SLAM (4)

待办项:

  1. 用yaml写参数
  2. 读取yaml参数
  3. 用class包装frame,替代struct
  • 问题一: 解决了一个Clion运行很慢的问题,原因是Clion用java写的,内存需求很大,原本是2G,我改成6G了,在Help->Change Memory Setting即可更改.

  • 问题二: 在我自己封装的slamBase库的compute_KeyPoints_Desp()函数中,用了自定义的kp和desp,而没用frame.kp,因此后面找不到match,因为根本没有储存下来.

  • 问题三: 点云凸出来的部分不完整,而且本来是平面的地方变成了上下的形状, 如下图所示,


    bad_cloudPoint.png
  • 解决: 通过joinCloud有问题->单个的cloud也有问题,说明image2Cloud这一步骤出了问题. 通过debug发现计算算法没问题,最后发现问题出现在depth图片imread()时, 忘记加-1这个参数.

    // 读取图像
    frame1.rgb = cv::imread("../data/rgb1.png");
    frame1.depth = cv::imread("../data/depth1.png", -1); //flag=-1时,8位深度,原通道
    frame2.rgb = cv::imread("../data/rgb2.png");
    frame2.depth = cv::imread("../data/depth2.png", -1); //flag=-1时,8位深度,原通道
joint_cloudPoint.png

RGBD-SLAM (5)

  • 问题一: inline 函数的功能以及使用方法,注意要将inline 函数放在.h文件,且它的声明和定义是放在一起的
// getDefaultCamera
// 输出: Camera参数
inline static CAMERA_INTRINSIC_PARAMETERS getDefaultCamera()
{
    ParameterReader pd;
    CAMERA_INTRINSIC_PARAMETERS camera;
    camera.fx = atof( pd.getData( "camera.fx" ).c_str());
    camera.fy = atof( pd.getData( "camera.fy" ).c_str());
    camera.cx = atof( pd.getData( "camera.cx" ).c_str());
    camera.cy = atof( pd.getData( "camera.cy" ).c_str());
    camera.scale = atof( pd.getData( "camera.scale" ).c_str() );
    return camera;
}
  • 问题二: 运行一会儿出现
Reading files 93
Find total 500 matches.
min dis = 4.12311
solving PnP
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.10-pre) /home/weiheng/Downloads/opencv/opencv/modules/calib3d/src/calibration.cpp:1099: error: (-2:Unspecified error) in function 'void cvFindExtrinsicCameraParams2(const CvMat*, const CvMat*, const CvMat*, const CvMat*, CvMat*, CvMat*, int)'
> DLT algorithm needs at least 6 points for pose estimation from 3D-2D point correspondences. (expected: 'count >= 6'), where
>     'count' is 5
> must be greater than or equal to
>     '6' is 6

Aborted (core dumped)

  • 解决方案:修改confidence从0.99变为0.95
    // 求解pnp
    cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 0.95 , inliers );
  • 问题三:g2o的初始化报错

    • 解决方法:

      // 选择优化方法
      typedef g2o::BlockSolver_6_3 SlamBlockSolver;
      typedef g2o::LinearSolverCSparse<SlamBlockSolver::PoseMatrixType> SlamLinearSolver;
      
      // 初始化求解器
      // SlamLinearSolver* linearSolver = new SlamLinearSolver();
      std::unique_ptr<SlamBlockSolver::LinearSolverType> linearSolver(new SlamLinearSolver);
      
      //linearSolver->setBlockOrdering(false);
      // SlamBlockSolver* blockSolver = new SlamBlockSolver(unique_ptr<SlamBlockSolver::LinearSolverType>(linearSolver));
      std::unique_ptr<SlamBlockSolver> blockSolver(new SlamBlockSolver(std::move(linearSolver)));
      
      // g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(blockSolver);
      g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(std::move(blockSolver));
      

问题四:读取.txt文件的rgb和depth序列号
解决:首先是stoi(), stod(), stold()的精度问题,其次是 std::cout << setprecision(20)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容