ORB_SLAM2--源码编译

前言

学习ORB_SLAM2,从编译源码开始

ORB_SLAM2的github地址: https://github.com/raulmur/ORB_SLAM2

一、准备工作:

 1.安装依赖库:

sudo apt install cmake
sudo apt install libgl1-mesa-dev
sudo apt install libeigen3-dev
sudo apt install libglew-dev freeglut3-dev

2.安装Pangolin:

git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin/
mkdir build
cmake ..
make -j4
sudo make install
# 默认安装在/usr/local/bin/Plotter

3.编译ORB_SLAM2:

git clone https://github.com/raulmur/ORB_SLAM2.git
cd ORB_SLAM2
chmod +x build.sh
./build.sh
# 如果编译过程中死机,将build.sh中的make -j改为make -j4

如果编译的过程中, 发现有usleep()函数的报错, 可以把报错的文件中添加头文件: #include <unistd.h>

# 一个小技巧, 搜索所有包含"usleep"字符串的文件
grep -r -e "usleep" ./Examples/
grep -r -e "usleep" ./src/

# 然后手动为这些文件添加: #include <unistd.h>

我编译过程中遇到的其他问题:

error: static assertion failed: std::map must have the same value_type as its allocator

解决方法:https://blog.csdn.net/lixujie666/article/details/90023059

打开LoopClosing.h,将

typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
        Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;

改为

typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
        Eigen::aligned_allocator<std::pair<KeyFrame *const, g2o::Sim3> > > KeyFrameAndPose;

二、运行例程:

下载测试数据: https://vision.in.tum.de/rgbd/dataset/freiburg1/rgbd_dataset_freiburg1_desk.tgz

然后执行:

cd ORB_SLAM2/
mkdir sequence
# 然后把文件解压到sequence文件夹下

# 运行例程
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml sequence/rgbd_dataset_freiburg1_desk

可以看到演示:

三、有关ros的安装:

1.先安装ros

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
sudo apt update

# Ubuntu16的安装指令:
sudo apt-get install ros-melodic-desktop
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo ln -s /home/jeff/study/ORB_SLAM2/Examples/ROS/ORB_SLAM2 /opt/ros/melodic/share/ORB_SLAM2 # 第一个路径换成自己的

# Ubuntu20的安装指令:
sudo apt install ros-noetic-desktop
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo ln -s /home/jeff/study/ORB_SLAM2/Examples/ROS/ORB_SLAM2 /opt/ros/noetic/share/ORB_SLAM2

sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool
sudo rosdep init # 网络问题可能需要更改网络多次尝试
rosdep update

2.运行build_ros.sh

./build_ros.sh
source Examples/ROS/ORB_SLAM2/build/devel/setup.bash

如果报错:

[100%] Linking CXX executable ../MonoAR
/usr/bin/ld: warning: libopencv_imgproc.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, may conflict with libopencv_imgproc.so.3.4
/usr/bin/ld: CMakeFiles/MonoAR.dir/src/AR/ViewerAR.cc.o: undefined reference to symbol '_ZN2cv7putTextERKNS_17_InputOutputArrayERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_6Point_IiEEidNS_7Scalar_IdEEiib'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.2.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/MonoAR.dir/build.make:248:../MonoAR] 错误 1
make[1]: *** [CMakeFiles/Makefile2:487:CMakeFiles/MonoAR.dir/all] 错误 2
make: *** [Makefile:130:all] 错误 2

需要安装opencv4.2,之后再重新运行./build.sh

下载解压opencv4.2:https://github.com/opencv/opencv/archive/4.2.0.zip

cd opencv-4.2.0
mkdir build
cd build
cmake ..
make -j8
sudo make install

3.编译调用笔记本自带摄像头的代码:

参考:https://www.cnblogs.com/feifanrensheng/p/8995836.html

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
source devel/setup.bash
cd ~/catkin_ws/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ..
catkin_make
source ~/catkin_ws/devel/setup.bash
roscd usb_cam # 没报错算成功

4.ros调用AR:

用笔记本自带的摄像头,需要把ros_mono_ar.cc中的:ros::Subscriber sub = nodeHandler.subscribe("/camera/image_raw", 1, &ImageGrabber::GrabImage,&igb);

改为:ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);,再重新编译。

开启一个终端,运行:

roscore

再开启一个终端,运行:

source ~/catkin_ws/devel/setup.bash
cd ~/catkin_ws/src/usb_cam/launch/
roslaunch usb_cam usb_cam-test.launch # 可以看到笔记本摄像头的画面

在ORB_SLAM2目录下开启第三个终端,运行:

rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml 

 

  • 1
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值