ORB-SLAM2+Ubuntu18.04配置与运行

1.基础工具

sudo apt-get install git
sudo apt-get install cmake
sudo apt-get install g++ gcc

2.安装所需依赖

1.Pangolin0.5

        0.5版本可以避免Eigen3的依赖错误,下载链接:Pangolin0.5-C++文档类资源-CSDN下载Pangolin0.5更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/w_fla/85345297

cd Pangolion
mkdir build && cd build
cmake ..
make -j8
sudo make install

    Pangolin测试:cd  Pangolin/examples/HelloPangolin,  mkdir build && cd build,  cmake ..,  make,  ./HelloPangolin。

2.Opencv3.2

ubuntu18.04默认安装,可忽略该步骤。

3.安装Eigen

sudo apt install  libeigen3-dev

3.下载ORB-SLAM2与编译

git clone https://github.com/raulmur/ORB_SLAM2.git
cd ORB-SLAM2
chmod +x build.sh

  build.sh文件修改如下:

echo "Configuring and building Thirdparty/DBoW2 ..."

cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8

cd ../../g2o

echo "Configuring and building Thirdparty/g2o ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8

cd ../../../

echo "Uncompress vocabulary ..."

cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
cd ..

echo "Configuring and building ORB_SLAM2 ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8

在下列文件中添加#include:

src/LocalMapping.cc,src/System.cc,src/LoopClosing.cc,src/Tracking.cc,src/Viewer.cc,Examples/Monocular/mono_tum.cc,Examples/Monocular/mono_kitti.cc,Examples/Monocular/mono_curoc.cc,Examples/RGB_D/rgbd_tum.cc,Examples/Stereo/stereo_kitti.cc,Examples/Stereo/stereo_curoc.cc。

编译:./build.sh

4.测试

在ORB-SLAM2文件夹下新建Data文件夹,下载https://vision.in.tum.de/rgbd/dataset/freiburg1/rgbd_dataset_freiburg1_xyz.tgz

解压到Data文件夹下。

cd ORB-SLAM2安装目录
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/cular/TUM1.yaml ./Data/rgbd_dataset_freiburg1_xyz

5.ORB_SLAM2运行自己的USB摄像头(单目)

准备工作:ORB-SLAM2+Ubuntu18.04配置与运行_第1张图片

         这三个.so文件一定要在该目录下存在,可用下面方式找到文件路径复制过来。

        cmakelist.txt修改:set中添加最后两行

ORB-SLAM2+Ubuntu18.04配置与运行_第2张图片

1.编译build_ros.sh

 sudo gedit ~/.bashrc 
//末尾添加代码段如下
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/自己的目录/ORB_SLAM2/Examples/ROS
source ~/.bashrc 
echo $ROS_PACKAGE_PATH//检验 ROS path 是否被识别

出现结果:/home/wl/ORB_SLAM/ORB_SLAM2/Examples/ROS表示成功

注:在这里不建议直接使用build_ros.sh直接编译,在/Examples/ROS文件夹终端下运行下列指令:

mkdir build && cd build
cmake ..
make

2.USB摄像头标定

        首先下载usb摄像头驱动:

cd catkin_ws/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git  
cd ..  
catkin_make  

        usb_cam-test.launch文件:


 
    //这里/dev/video0表示打开笔记本摄像头,/dev/video1打开自己外接的摄像头,根据自己需要修改
   
   
   
   
   
 

 
   
   
 

        下载usb摄像头标定包进行标定:参考博客ROS系统-摄像头标定camera calibration_berry丶的博客-CSDN博客_ros标定摄像头icon-default.png?t=M4ADhttps://blog.csdn.net/zbr794866300/article/details/94862108

3.文件修改

    1.ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);

  /usb_cam/image_raw为使用的摄像头节点,可用rostopic list查看。ORB-SLAM2+Ubuntu18.04配置与运行_第3张图片

         2.在该图中新建my.yaml,内容如下:

%YAML:1.0

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------

# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 613.34257
Camera.fy: 609.97127
Camera.cx: 353.59088
Camera.cy: 209.10541

Camera.k1: -0.204398
Camera.k2: 0.371587
Camera.p1: -0.004708
Camera.p2: 0.008199

Camera.width: 640
Camera.height: 480   #该部分为上一步标定结果的参数对应Asus.yaml文件格式改写

# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1

# Close/Far threshold. Baseline times.
ThDepth: 40.0

# Deptmap values factor
DepthMapFactor: 1.0

#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------

# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1000

# ORB Extractor: Scale factor between levels in the scale pyramid     
ORBextractor.scaleFactor: 1.2

# ORB Extractor: Number of levels in the scale pyramid    
ORBextractor.nLevels: 8

# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast            
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7

#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500

4.测试

roslaunch usb_cam usb_cam-test.launch
rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt  Examples/ROS/ORB_SLAM2/my.yaml//在ORB_SLAM2路径终端下运行

ORB-SLAM2+Ubuntu18.04配置与运行_第4张图片

 

你可能感兴趣的:(ros,ubuntu,linux,运维)