###将ygz_slam_ros单独拿出来编译
#按照安装依赖
https://gaas.gitbook.io/guide/software-realization-build-your-own-autonomous-drone/wu-ren-ji-zi-dong-jia-shi-xi-lie-part-3-zai-wu-gps-huan-jing-xia-tong-guo-slam-shi-xian-wei-zhi-gu-j
Mavros msgs: sudo apt install ros-kinetic-mavros-msgs
Pangolin (for visualization): https://github.com/stevenlovegrove/Pangolin
Eigen3: sudo apt-get install libeigen3-dev
g2o: sudo apt-get install libcxsparse-dev libqt4-dev libcholmod3.0.6 libsuitesparse-dev qt4-qmake
glog (for logging): sudo apt-get install libgoogle-glog-dev
ROS Octomap: sudo apt-get install ros-kinetic-octomap-*
#用以下命令,但不包括安装Pangolin
sudo apt-get install libeigen3-dev
sudo apt-get install ros-kinetic-mavros-msgs
sudo apt-get install libqglviewer-headers libqt4-dev libcholmod3 libsuitesparse-dev qt4-qmake
sudo apt-get install libgoogle-glog-dev
sudo apt-get install ros-kinetic-octomap-*
sudo apt-get install libglew-dev
sudo apt-get install libxkbcommon-x11-dev
#安装g2o依赖报错
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros$ sudo apt-get install libcxsparse-dev libqt4-dev libcholmod3.0.6 libsuitesparse-dev qt4-qmake
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libcxsparse-dev
#解决:进入https://github.com/RainerKuemmerle/g2o进行安装
#按照教程https://www.cnblogs.com/ambition921009/p/10551959.html
1、首先在github上下载g2o图优化库
git clone https://github.com/RainerKuemmerle/g2o.git
2、运行安装以下依赖库
sudo apt-get install libcholmod3.0.6
sudo apt-get install libsuitesparse-dev
sudo apt-get install freeglut3 freeglut3-dev freeglut3-dbg
sudo apt-get install libqglviewer2 libqglviewer-dev libqglviewer-doc
sudo apt-get install libeigen3-dev libeigen3-doc
3、开始安装g2o,先进入g2o的目录内,然后开启终端,依次运行下列命令:
mkdir build
cd build/
cmake ..
make
sudo make install
至此,g2o图优化库安装完毕!
##安装PCL
https://github.com/PointCloudLibrary/pcl
git clone https://github.com/PointCloudLibrary/pcl pcl-trunk
cd pcl-trunk && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j2
sudo make -j2 install
##安装DBoW3
cd Thirdparty/DBow3/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4
##安装fast
cd ../../fast
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4
##安装opencv
#在编译opencv的过程中,需要确保cmake生成的opencv编译配置中,包括了opencv_cvv组件。为此,你需要首先克隆opencv_contrib:
git clone https://github.com/opencv/opencv_contrib
#进入克隆下来的opencv目录,切换版本到一个较高版本——此处使用版本号3.4.5:
git checkout 3.4.5
#注意,对于opencv和opencv_contrib都需要切换版本,且必须保证两者版本一致。
#然后使用cmake进行配置——若对cmake不熟悉则可以使用cmake-gui:
sudo apt-get install cmake-qt-gui
cmake-gui
##上面比较抽象,以下是具体的操作
参考教程:https://blog.csdn.net/echoamor/article/details/83022352
1.先去github上下载opencv和opencv_contrib,并在分支中(左上角Tag那里选)选择相对应的版本,如都是3.4.5.
https://github.com/opencv/opencv/tree/3.4.5
https://github.com/opencv/opencv_contrib/tree/3.4.5
2.安装依赖
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
3.依赖安装完成后,把opencv_contrib文件夹放入opencv目录下,并且创建build文件夹
4.安装cmake-gui
sudo apt-get install cmake-gui
5.安装配置opencv
安装好之后,进入opencv文件夹里的build文件夹,在这里打开终端,输入:
cmake-gui ..
6.确定路径没问题之后点击configure选择Unix Makefiles,其余默认,点击finish。需要下载一些文件,要等待一段时间。然后CMake即载入默认配置.
7.这里需要对三个地方进行修改:
(1)在CMAKE_BUILD_TYPE 值处输入RELEASE,其他保持不变(如果已经存在就不必修改)。
下方的CMAKE_INSTALL_PREFIX显示了默认的安装目录,生成makefile文件最后执行 make install时就会安装到这个目录,这里可以根据个人需求更改。但是建议就按照默认路径来,不要乱改!
(2)在OPENCV_EXTRA_MODULES_PATH处,选择输入目录(单击这一行后方空白处即可选中)
接着选择opencv_contrib文件夹中的modules文件夹,注意,不是只选中opencv_contrib文件夹就好了,需要点进去选中里面的modules文件夹! 然后点Choose。
(3)在BUILD_opencv_world后面打√
(4)勾选WITH_QT和ENABLE_CXX11:
8.再点击一次Configure,即可看到BUILD_opencv_cvv选项,勾选之后点击Generate即可生成目标makefile,进行编译即可。这个过程需要一段时间,耐心等待一下。完成后显示generating done
9.完成之后,在build文件夹下重新打开一个终端,输入make,就会开始编译,过程较长,耐心等待。
10.配置环境变量
(1)安装成功后还需要设置opencv的环境变量。打开文件:
sudo gedit /etc/ld.so.conf.d/opencv.conf
(2)将以下内容添加到最后:
/usr/local/lib
(3)接下来配置库:
sudo ldconfig
(4)更改环境变量:
sudo gedit /etc/bash.bashrc
(5)在文件后添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存退出,到这一步,opencv安装完成!
原文链接:https://blog.csdn.net/echoamor/article/details/83022352
注意:按照步骤7设置之后不能编译成功。后来采用以下步骤:
4.安装cmake-gui
sudo apt-get install cmake-gui
5.安装配置opencv
安装好之后,进入opencv文件夹里的build文件夹,在这里打开终端,输入:
cmake-gui ..
6.首先指定编译目录,source code选择opencv的目录,build the binaries选择opencv的build,点击Configure并选择Unix Makefiles,先进行第一次配置:
7.指定OPENCV_EXTRA_MODULES_PATH到opencv_contrib的modules,并勾选WITH_QT和ENABLE_CXX11:
再点击一次Configure,即可看到BUILD_opencv_cvv选项,勾选之后点击Generate即可生成目标makefile,进行编译即可。
即回到opencv/build目录下,make.
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros$ cd opencv
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros/opencv$ cd build/
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros/opencv/build$ cmake-gui ..
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros/opencv/build$ make
编译过程需要很长时间,编译opencv需要大量内存。
#安装
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros/opencv/build$ sudo make install
#配置按照以上步骤
10.配置环境变量
(1)安装成功后还需要设置opencv的环境变量。打开文件:
sudo gedit /etc/ld.so.conf.d/opencv.conf
(2)将以下内容添加到最后:
/usr/local/lib
(3)接下来配置库:
sudo ldconfig
(4)更改环境变量:
sudo gedit /etc/bash.bashrc
(5)在文件后添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存退出,到这一步,opencv安装完成!
##编译SLAM
#由于ROS自带了低版本的opencv,为了防止cmake在生成SLAM的makefile的过程中无法找到正确的opencv版本,需要在SLAM的cmake配置文件中指定:
cd /MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros
gedit CMakeLists.txt
配置文件的第53行:
find_package(OpenCV REQUIRED)
在OpenCV后面加上版本号(注意不要省略空格),若你安装了其他版本(必须不低于3.4.5),则将3.4.5改为你安装的版本号:
find_package(OpenCV 3.4.5 REQUIRED)
#完成后,通过如下命令编译SLAM:
cd (GAAS_PATH)/software/SLAM/ygz_slam_ros
cd ~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros
# 编译过程较长,不建议在虚拟机里进行
sh generate.sh
#运行测试
#启动小觅SDK ROS节点
cd MYNT-EYE-ORB_SLAM2/src/MYNT-EYE-S-SDK/
source ./wrappers/ros/devel/setup.bash
roslaunch mynt_eye_ros_wrapper mynteye.launch
#查看节点话题
/mynteye/left/image_raw
/mynteye/right/image_raw
#在 ygz_slam_ros/examples文件夹内,你可以看到一个名为simulationCamera.yaml的配置文件,此文件是SLAM的配置文件,文件包含ROS的左右图像topic名,相机内参以及一些其它参数。其中一部分内容如下:
......
# camera and imu topics
Left: /gi/simulation/left/image_raw
Right: /gi/simulation/right/image_raw
......
如果想测试自己的相机,请更改相机topic,注意此时并没有使用IMU信息,并且此项目还未完成,会有不稳定情况出现。
将话题改成自己的双目话题:
Left: /mynteye/left/image_raw
Right: /mynteye/right/image_raw
#接下来,开启SLAM:
./bin/EurocStereoVIO_ros ./examples/simulationCamera.yaml
#报错
chen@chen:~/MYNT-EYE-ORB_SLAM2/src/ygz_slam_ros$ ./bin/EurocStereoVIO_ros ./examples/simulationCamera.yaml
OpenCV Error: Parsing error (./examples/simulationCamera.yaml(10): Tabs are prohibited in YAML!) in icvYMLSkipSpaces, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/persistence.cpp, line 1322
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/persistence.cpp:1322: error: (-212) ./examples/simulationCamera.yaml(10): Tabs are prohibited in YAML! in function icvYMLSkipSpaces
Aborted (core dumped)
#待解决...