一、配置ORB_SLAM2过程
sudo apt-get install libglew-dev
sudo apt-get install libpython2.7-dev
sudo apt-get install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev
sudo apt-get install libdc1394-22-dev libraw1394-dev
sudo apt-get install libjpeg-dev libtiff5-dev libopenexr-dev
2、安装Pangolin:
cd ~
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make -j4
sudo make install
3、opencv
Jetpack4.5 给TX2安装的opencv版本是4.1.1,我后面编译orb_slam2的时候,报错是找不到opencv,ORB_SLAM2上也是只支持到3,为了避免麻烦,干脆就一刀切,opencv换成了3.4.7版本的,4版本的可能也可以弄,我没试过。
sudo apt-get purge libopencv*
运行这句话,看到后面删掉了好多ros里面的东西,感觉还是要慎重,后面直接心一横把ros也卸载了重新再装一遍
先卸载包
sudo apt-get purge ros-*
再卸载依赖包
sudo apt-get autoremove
然后开始卸载opencv
sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update
重新安装opencv3.4.7按照之前写的博客操作
make -j4时有个报错:
/home/yxin/opencv/3.4.7/opencv-3.4.7/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: 没有那个文件或目录
# include <Eigen/Core>
^~~~~~~~~~~~
compilation terminated.
modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o' failed
解决办法:
没安装eigen库的话,
执行命令:
sudo apt-get install libeigen3-dev
我已经安装了eigen库,虽然安装了Eigen库,但是编译时找不到相应文件,因为我们默认的安装地址是/usr/include/eigen3/Eigen,我们可以把它映射到/usr/include下
执行命令:
sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
也可以引入Eigen头文件,在CMakeLists.txt里添加Eigen头文件的目录。
如:include_directories("/usr/include/eigen3")
验证一下:
pkg-config --modversion opencv
显示3.4.7
python3 #python2相同
import cv2
cv2.__version__
显示3.4.7
4、DBoW2和g2o
可以一起在ORB_SLAM2中编译
5、编译ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh
二、运行单目的例子
数据集:从http://vision.in.tum.de/data/datasets/rgbd-dataset/download下载序列并解压缩
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml rgbd_dataset_freiburg1_xyz
结果如图:
三、 摄像头信息的读取和显示
1、创建初始化工作目录:
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
2、添加环境变量:
gedit ~/.bashrc
添加如下代码:
# Set ROS Network
export ROS_HOSTNAME=xxx.xxx.xxx.xxx
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
# Set ROS alias command
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
ROS_HOSTNAME=xxx.xxx.xxx.xxx 可以是本机的IP,也可以是localhost
#Set ROS Network
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311
3、下载usb_cam包
cd src
git clone https://github.com/bosch-ros-pkg/usb_cam.git usb_cam
4、编译工作空间
cd ..
catkin_make
roslaunch usb_cam usb_cam-test.launch
5、将摄像头的连接线插入电脑的USB接口
6、启动usb_cam节点
roslaunch usb_cam usb_cam-test.launch
报错:
RLException: [usb_cam-test.launch] is neither a launch file in package [usb_cam] nor is [usb_cam] a launch file name
The traceback for the exception was written to the log file
解决办法:
在bashrc中加入环境变量:source ~/catkin_ws/devel/setup.bash
报错:
[ERROR] [1618282028.556966973]: Couldn’t query v4l fps! error 25, Inappropriate ioctl for device
[usb_cam-2] process has died [pid 16793, exit code 1, cmd /home/yxin/catkin_ws/devel/lib/usb_cam/usb_cam_node __name:=usb_cam __log:=/home/yxin/.ros/log/885405d8-9c02-11eb-b3f3-00044bde5166/usb_cam-2.log].
log file: /home/yxin/.ros/log/885405d8-9c02-11eb-b3f3-00044bde5166/usb_cam-2*.log
解决办法:
catkin_ws/src/usb_cam/launch/usb_cam-test.launch中
<param name="video_device" value="/dev/video0" />
修改为:
<param name="video_device" value="/dev/video1" />
TX2默认用的是板载的CSI摄像头
四、Ros上运行ORB_SLAM2
1、已经创建了工作空间catkin_ws,将ORB-SLAM2项目移动到其子文件夹src下。
(1)将包含Examples/ROS/ORB_SLAM2的路径添加到ROS_PACKAGE_PATH环境变量中。打开.bashrc文件并在最后添加以下行。
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS
其中PATH为ORB-SLAM2项目所在路径,我的路径为/home/yuxin/catkin_ws/src。此外,还要在./bashrc文件写入
source /home/yuxin/catkin_ws/devel/setup.sh
最后在终端执行命令
source ./bashrc
2、编译ROS下的ORB-SLAM2
ORB-SLAM默认订阅的话题为/camera/image_raw,而usb_cam节点发布的话题为/usb_cam/image_raw,因此需要在ORB_SLAM2/src/ros_mono.cc中修改订阅的话题,这点要特别注意。因为源文件的更改必须要重新编译。
删除掉ORB_SLAM2中的build文件夹,Thirdparty中两个库的build文件夹重新编译:./build.sh
报错:
catkin_ws/src/ORB_SLAM2/src/System.cc:134:28: error: ‘usleep’ was not declared in this scope usleep(1000);等等很多个,在相应的文件上添加:
#include <unistd.h>
再编译ros
chmod +x build_ros.sh
./build_ros.sh
还有上一步中的报错,继续添加
#include <unistd.h>
报错:
usr/bin/ld: CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: undefined
reference to symbol ‘_ZN5boost6system15system_categoryEv’
/usr/lib/x86_64-linux-gnu/libboost_system.so: 无法添加符号: DSO missing from
command line collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:182: recipe for target ‘…/Stereo’
failed make[2]: *** […/Stereo] Error 1 CMakeFiles/Makefile2:104:
recipe for target ‘CMakeFiles/Stereo.dir/all’ failed make[1]: ***
[CMakeFiles/Stereo.dir/all] Error 2
解决办法:
打开Examples/ROS/ORB_SLAM2/CMakeLists.txt
下面代码增加 -lboost_system,在重新编译。
set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
-lboost_system
)
出错原因是libboost_system.so 与libboost_filesystem.so找不到链接目录
查找boost_system和boost_filesystem的目录,参考这里
locate boost_system
......
locate boost_filesystem
......
运行以下命令:
sudo cp /usr/lib/aarch64-linux-gnu/libboost_system.so //home/yxin/catkin_ws/src/ORB_SLAM2/lib
sudo cp /usr/lib/aarch64-linux-gnu/libboost_system.so.1.65.1 /home/yxin/catkin_ws/src/ORB_SLAM2/lib
sudo cp /usr/lib/aarch64-linux-gnu/libboost_filesystem.so /home/yxin/catkin_ws/src/ORB_SLAM2/lib
sudo cp /usr/lib/aarch64-linux-gnu/libboost_filesystem.so.1.65.1 /home/yxin/catkin_ws/src/ORB_SLAM2/lib
编译过后有关于opencv的警告出现,后面运行的时候没有什么影响。
3、运行单目节点
运行单目节点前要先将摄像头接入电脑,然后启动usb_cam节点。
roslaunch usb_cam usb_cam-test.launch
在ORB_SLAM2下另开终端运行
rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml
真好直接出结果了: