ROS跑ORB_SLAM2 电脑相机
安装usb_cam
//把usb_cam放到orb_slam2_ws/src下
cd catkin_ws/src/usb_cam
mkdir build
cd build
cmake ..
make
方法2
sudo apt-get install ros-noetic-usb-cam
根据ros不同版本更改命令
测试
roslaunch usb_cam usb_cam-test.launch
在运行节点之前配置一下节点参数,打开src/usb_cam-develop/launch文件,确认设备号即可,电脑自带相机的设备号是video0。
ros环境下编译orb_slam2功能包
1. 在~/.bashrc中配置一下环境
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/zwq-slamer/orb_slam2_ws/src/ORB_SLAM2/Examples/ROS
2.编译orb_slam2功能包
cd orb_slam2_ws/src/ORB_SLAM2/
chmod +x build.sh
./build.sh
./buils_ros.sh
编译过程中会报错
error1:编译build.sh时,报错内容就是编译orb_slam2时相同的报错内容,根据报错内容bing一下,改完相应文件之后重新编译即可。
error2:编译build_ros.sh时,大量usleep报错,没顾上截图,类同
/home/hazyparker/project/ORB_SLAM2/src/System.cc: In member function ‘cv::Mat ORB_SLAM2::System::TrackStereo(const cv::Mat&, const cv::Mat&, const double&)’:
/home/hazyparker/project/ORB_SLAM2/src/System.cc:134:17: error: ‘usleep’ was not declared in this scope
usleep(1000);
^~~~~~
/home/hazyparker/project/ORB_SLAM2/src/System.cc:134:17: note: suggested alternative: ‘fseek’
usleep(1000);
^~~~~~
fseek
/home/hazyparker/project/ORB_SLAM2/src/System.cc: In member function ‘cv::Mat ORB_SLAM2::System::TrackRGBD(const cv::Mat&, const cv::Mat&, const double&)’:
/home/hazyparker/project/ORB_SLAM2/src/System.cc:185:17: error: ‘usleep’ was not declared in this scope
usleep(1000);
^~~~~~
/home/hazyparker/project/ORB_SLAM2/src/System.cc:185:17: note: suggested alternative: ‘fseek’
usleep(1000);
^~~~~~
fseek
/home/hazyparker/project/ORB_SLAM2/src/System.cc: In member function ‘cv::Mat ORB_SLAM2::System::TrackMonocular(const cv::Mat&, const double&)’:
/home/hazyparker/project/ORB_SLAM2/src/System.cc:236:17: error: ‘usleep’ was not declared in this scope
usleep(1000);
^~~~~~
/home/hazyparker/project/ORB_SLAM2/src/LoopClosing.cc: In member function ‘void ORB_SLAM2::LoopClosing::Run()’:
/home/hazyparker/project/ORB_SLAM2/src/LoopClosing.cc:84:9: error: ‘usleep’ was not declared in this scope
usleep(5000);
^~~~~~
根据log看哪个文件报错,就在哪个文件下添加#include<unistd.h>
基本在Example/ROS文件夹下的所有cc文件添加该头文件。
error3:类同如下日志
/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.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/RGBD.dir/build.make:213: recipe for target '../RGBD' failed
make[2]: *** [../RGBD] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/RGBD.dir/all' failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
/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:213: 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
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
DSO missing from command
猜测大概是动态库的链接问题
bing相关内容后,解决方案
在~orb_slam2_ws/src/ORB_SLAM2/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
)
之后再编译,编译崩溃的点往后延了百分之多少,还是有DSO missing from command line
,同时还有大量OpenCV版本的warning
大致意思是所需4.2与现有的3.4.1的冲突
查询自己电脑有的opencv的版本
zwq-slamer@ubuntu-to-go:~$ pkg-config --modversion opencv
3.4.1
zwq-slamer@ubuntu-to-go:~$ pkg-config --modversion opencv4
4.2.0
查找到自己电脑有3.4.1和4.2.0两个版本。其中3.4.1是自己安装的,4.2猜测可能是ROS noetic自带的
遂尝试修改CMakeLIsts.txt文件里面 find package (OpenCV 4.2 QUIET)
注意:ORB_SLAM2主目录下和Thirdparty 下以及Example/ros下的所有CMakeLists.txt文件都改。不然warning一大堆,且编译成功之后运行也是出现段错误
3. 尝试运行orb_slam2
roscore
roslaunch usb_cam
roslaunch usb_cam usb_cam-test.launch
rosrun ORB_SLAM2 Mono VOcabulary/ORBvoc.txt Example/Monocular/TUM1.yaml
直接段错误。
解决方案:尝试排查之前操作的漏洞,之后把所有的CMakeLists文件都修改之后运行./build.sh文件和./build_ros.sh文件。
之后再次运行
成功出现orb_slam2可视化窗口,不过跑一会儿就崩溃掉,同样显示段错误。多次反复尝试,一直就是Try Initialing。比之前强的是可以成功跑出图像来。
猜测我用的自己电脑的相机但是用的TUM数据集相机的参数配置文件。故尝试用棋盘格来标定自己电脑的相机。
4. 标定相机
[link]https://blog.csdn.net/lemonxiaoxiao/article/details/107719348
1、安装功能包
sudo apt-get install ros-noetic-camera-calibration
2、启动相机节点
rosrun usb_cam usb_cam_node
3、运行标定节点
rosrun camera_calibration cameracalibrator.py --size 7x9 --square 0.1 image:=/usb_cam/image_raw camera:=/head_camera --no-service-check
成功打开标定窗口
网图,类似。
直到条形变为绿色。当calibration按钮亮起时,代表已经有足够的数据进行摄像头的标定,此时请按下calibration并等待一分钟左右,标定界面会变成灰色,无法进行操作,属于正常情况。
点击Save按钮,标定文件夹会保存在home文件夹下。把camera matrix的参数按照TUM.yaml文件的格式保存一个自己相机的yaml文件。
运行orb_slam2节点
标定好相机之后用自己的配置文件跑一下还是初始化阶段就崩,没法完成初始化,电脑动一下就段错误。
解决方案:把所有CMakeLists文件 march=native
删掉,重新编译
执行
./build.sh
./build_ros.sh
成功初始化。