运行环境:
docker、ubuntu18.04、ros melodic
此前,大家在github issues中反馈了较多关于opencv版本导致的编译和运行问题。作者建议opencv的版本要在3.3以上,基于opencv 3.3.1, 3.4.16, 4.2.1 and 4.5.3,作者做过测试,均能成功运行。ros melodic自带opencv3.2.0,确实如果不更换版本的话会遇到问题。
本文以3.3.1为例,介绍如何在上述运行环境下编译运行r3live。
1. 安装ros依赖
sudo apt-get install ros-melodic-cv-bridge ros-melodic-tf ros-melodic-message-filters ros-melodic-image-transport*
2. 安装livox_ros_driver
mkdir -p ws_livox/src
cd ws_livox/src
git clone https://github.com/Livox-SDK/livox_ros_driver.git
cd ..
catkin_make
source ./devel/setup.sh(或者将其添加到.bashrc中,这样就不必每次执行source)
3. 安装CGAL and pcl_viewer (optional)
sudo apt-get install libcgal-dev pcl-tools
4. 安装配置opencv3.3.1
查看当前环境opencv版本:
pkg-config --modversion opencv
源码编译安装opencv3.3.1:
sudo apt-get update
1. 确保已安装必要的依赖项和库:
sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk-3-dev libatlas-base-dev gfortran python2.7-dev python3-dev
2. 下载OpenCV 3.3.1源代码:
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.3.1.zip
unzip opencv.zip
3. cd ~/opencv-3.3.1/
mkdir build
cd build
4. 运行CMake以配置OpenCV编译:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON ..
或者直接cmake ..
5. 编译OpenCV:
make -j4
6. 安装OpenCV:
sudo make install
sudo ldconfig
7. 重启
修改cv_bridge配置:
ros默认安装的opencv路径在/usr/include,/usr/lib,/usr/share三个目录。从opencv官网源码编译安装的,opencv会默认安装到usr/local下对应的三个子目录。
cd /opt/ros/melodic/share/cv_bridge/cmake/
sudo gedit cv_bridgeConfig.cmake
在cv_bridgeConfig.cmake文件中分别搜索include和libraries,进行两处修改如下:
# if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
if(NOT "include;/usr/local/include;/usr/local/include/opencv " STREQUAL " ")
# set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0")
set(libraries "cv_bridge;/usr/local/lib/libopencv_core.so.3.3.1;/usr/local/lib/libopencv_imgproc.so.3.3.1;/usr/local/lib/libopencv_imgcodecs.so.3.3.1")
5. 编译r3live并运行
mkdir -p r3live/src
cd r3live/src
git clone https://github.com/hku-mars/r3live.git
cd ../
catkin_make
source devel/setup.bash
roslaunch r3live r3live_bag.launch
rosbag play YOUR_DOWNLOADED.bag
6. 参考: