ORB-SLAM2稠密建图编译/运行,遇到的坑(已解决!)

在使用./build.sh编译ORB_SLAM2_modified时,出现大量报错

/usr/include/pcl-1.10/pcl/point_types.h:478:1: error: ‘minus’ is not a member of ‘pcl::traits’
  478 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PointNormal,
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘divscalar’ is not a member of ‘pcl::traits’
  541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD,
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

类似于上面的错误,还有许多其他的报错,只能编译后,立马cltr+c停止编译,才能详细看到;

解决方案是:进入到ORB_SLAM2_modified所属文件夹的CMakeLists.txt里面,然后添加:

set(CMAKE_CXX_STANDARD 14)


部分内容如下:

include(CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)

CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

if(COMPILER_SUPPORTS_CXX11)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_definitions(-DCOMPILEDWITHC11)

message(STATUS "Using flag -std=c++11.")

elseif(COMPILER_SUPPORTS_CXX0X)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

add_definitions(-DCOMPILEDWITHC0X)

message(STATUS "Using flag -std=c++0x.")

else()

message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")

endif()

#加入的

set(CMAKE_CXX_STANDARD 14)

然后再次执行编译,编译通过!!

[ 94%] Linking CXX executable ../bin/stereo_euroc
[ 97%] Linking CXX executable ../bin/mono_tum
[100%] Linking CXX executable ../bin/mono_euroc
[100%] Built target stereo_euroc
[100%] Built target mono_tum
[100%] Built target mono_euroc
Converting vocabulary to binary
BoW load/save benchmark

再进行ROS功能包编译时,出现以下问题:

进行:

./build_ros.sh

发现问题:

  You should double-check your ROS_PACKAGE_PATH to ensure that packages are
  found in the correct precedence order.
Call Stack (most recent call first):
  /opt/ros/noetic/share/ros/core/rosbuild/public.cmake:177 (_rosbuild_check_package_location)
  CMakeLists.txt:7 (rosbuild_init)
-- Configuring incomplete, errors occurred!

原因是,我把ORB_SLAM2的功能包,以及稠密建图的功能包都放在一个工作空间下,有可能在ROS编译的时候,首先进入到了ORB_SLAM2当中,因此搜索不到这个包的ROS路径;

解决方法:

先删除ORB_SLAM2里面的ROS包,然后使用:
./build_ros.sh
重新编译这个包下的ROS,编译通过后,再从回收站复原就行

编译通过,但是运行稠密建图时,点云地图是灰色

解决方法:将ORB_SLAM2_map中的include文件夹中的Tracking.h打开

添加一行,以声明RGB矩阵:

Frame mCurrentFrame;
cv::Mat mImRGB;    //添加进去的
cv::Mat mImGray;

再进入到src/ORBSLAM2_with_pointcloud_map/ORB_SLAM2_modified/src/Tracking.cc中

添加两处:

cv::Mat Tracking::GrabImageRGBD(const cv::Mat &imRGB,const cv::Mat &imD, const double ×tamp)
{
mImRGB = imRGB;        // 新添加的
mImGray = imRGB;
......
mpPointCloudMapping->insertKeyFrame( pKF, this->mImGray, this->mImDepth );

mpPointCloudMapping->insertKeyFrame( pKF, this->mImRGB, this->mImDepth );//新添加的

然后进入到稠密建图的工作空间:

先编译:
chmod +x ./build.sh
./build.sh
再编译ROS空间:
chmod +x ./build_ros.sh
./build_ros.sh


之后再运行稠密重建,最后得到的地图就是彩色地图!!!

关于如何获取RGB-D相机内参(使用相机运行稠密重建):

首先启动ros核心:

roscore

然后确保自己安装了realsense_ros的情况下,使用:

realsense2_camera rs_rgbd.launch
#在执行launch之前,插上自己的深度相机;线要用USB3.0以上

上述的launch能够接受相机发送的信息,同时向外发布信息;

然后使用:

rostopic list
#打印话题

打印结果如下:

/camera/color/metadata
/camera/color_rectify_color/parameter_descriptions
/camera/color_rectify_color/parameter_updates
/camera/depth/camera_info
/camera/depth/image_rect_raw
/camera/depth/metadata
/camera/depth_registered/points
/camera/extrinsics/depth_to_color
/camera/motion_module/parameter_descriptions
/camera/motion_module/parameter_updates
/camera/realsense2_camera_manager/bond

结果有很多,但是我们只要camera_info结尾的,其中包含相机话题里的具体消息:

然后:

rostopic echo /camera/depth/camera_info

得到的结果非常多,因为连接着相机,会一直发布信息;使用ctrl + c终止打印;

然后就能得到:

header: 
  seq: 48
  stamp: 
    secs: 1689851344
    nsecs: 450543642
  frame_id: "camera_color_optical_frame"
height: 720
width: 1280
distortion_model: "plumb_bob"
D: [-0.05503007769584656, 0.07031764090061188, -0.0001770215021679178, 0.0002901298284996301, -0.022616472095251083]
K: [636.0006713867188, 0.0, 645.7568359375, 0.0, 635.2332153320312, 358.4593200683594, 0.0, 0.0, 1.0]
R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P: [636.0006713867188, 0.0, 645.7568359375, 0.0, 0.0, 635.2332153320312, 358.4593200683594, 0.0, 0.0, 0.0, 1.0, 0.0]
binning_x: 0
binning_y: 0
roi: 
  x_offset: 0
  y_offset: 0
  height: 0
  width: 0
  do_rectify: False

类似于这样的消息;上述信息包含:相机分辨率、相机深度、相机内参等等,根据需要,写入yaml文件,然后进行调用即可!例如,ORB_SLAM2的稠密重建调用:

 rosrun ORB_SLAM2 RGBD_WITH_MY_BAG Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/MyD435i.yaml 

这样就可以实时调用RGB-D相机稠密建图了!

运行稠密建图存在的问题:

[pcl::VoxelGrid::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow.

很多文章说,需要对PCL点云的尺寸进行修改;emmmm...我试了一下,稠密重建的质量严重下降,不建议直接修改尺寸。

参考文章:

Leaf size is too small for the input dataset 解决办法_Pxmzhao的博客-CSDN博客

使用D435i相机跑ORB-SLAM2_RGBD_DENSE_MAP-master稠密建图编译(实时彩色点云地图加回环+保存点云地图)_d435i slam_摆烂女侠的博客-CSDN博客

Ubuntu20.04配置ORBSLAM2并运行(保姆级教程)_orbslam2运行_9527风先生的博客-CSDN博客 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值