vins-fusion gpu, docker, opencv4.5.4(cuda) 復現

cold_moon發表於2024-10-29

程式碼:https://gitee.com/zheng-yongjie/vins-fusion-gpu-cv4?skip_mobile=true

硬體: jetson xavier nx, 系統 20.04

nvcc -V 可檢視cuda版本

本文在docker裡面復現

1. opencv cuda 安裝

root@ubuntu:~# pwd
/root

wget -O opencv-4.5.4.zip https://github.com/opencv/opencv/archive/4.5.4.zip # check version
wget -O opencv_contrib-4.5.4.zip wget https://github.com/opencv/opencv_contrib/archive/4.5.4.zip
unzip opencv.zip && unzip opencv_contrib-4.5.4.zip
cd opencv-4.5.4/ && mkdir build && cd build
cmake   -D CMAKE_BUILD_TYPE=RELEASE \
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.4/modules \
        -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
        -D CMAKE_INSTALL_PREFIX=/workspace/opencv-4.5.4 \
        -D WITH_CUDA=ON \
        -D CUDA_ARCH_BIN=7.2 \ # nx
        -D CUDA_ARCH_PTX=7.2 \
        -D ENABLE_FAST_MATH=ON \
        -D CUDA_FAST_MATH=ON \
        -D WITH_CUBLAS=ON \
        -D WITH_LIBV4L=ON \
        -D WITH_GSTREAMER=ON \
        -D WITH_GSTREAMER_0_10=OFF \
        -D WITH_QT=OFF \
        -D WITH_OPENGL=ON \
        -D CUDA_NVCC_FLAGS="--expt-relaxed-constexpr" \
        -D WITH_TBB=ON ..

export http_proxy=http://IP:7890 # 需要開啟 clash 中允許區域網連線
export https_proxy=http://IP:7890

make -j8
sudo make install # 安裝到:/workspace/opencv-4.5.4 下

# 刪除下載的安裝包即可。(可選)

pkg-config --modversion opencv4  # Check opencv Version

sudo find /workspace -name "OpenCVConfig.cmake" # 找到 OpenCVConfig.cmake 檔案
/workspace/opencv-4.5.4/lib/cmake/opencv4/OpenCVConfig.cmake

2. CV-Bridge的編譯

在安裝 OpenCV4 後必須重新構建 cv_bridge,這樣就不會發生 OutOfMemoryError。

https://github.com/ros-perception/vision_opencv/tree/noetic

直接下載 noetic zip。

root@ubuntu:~/vision_opencv-noetic# pwd
/root/vision_opencv-noetic
root@ubuntu:~/vision_opencv-noetic/cv_bridge# vim CMakeLists.txt # 修改為自己的 opencv 安裝路徑

 20 # set(_opencv_version 4)
 21 # 指定 OpenCVConfig.cmake 的路徑
 22 set(OpenCV_DIR "/workspace/opencv-4.5.4/lib/cmake/opencv4")
 
# 編譯
mkdir build && cd build
cmake ..
make -j8

3. Vins-Fusion GPU編譯安裝

root@ubuntu:/workspace# mkdir -p vins_fusion_gpu_catkin_ws/src 
root@ubuntu:/workspace# cd vins_fusion_gpu_catkin_ws/src && git clone https://gitee.com/jerry-ironman/vins-fusion-gpu-cv4.git 

# 在宿主機上更改程式碼庫許可權,以方便修改程式碼。
sudo chown -R 使用者名稱:使用者組 vins_fusion_gpu_catkin_ws

# 修改 cv_bridge_DIR 和 OpenCV_DIR
vim vins-fusion-gpu-cv4-master/vins_estimator/CMakeLists.txt
 9 set(cv_bridge_DIR /root/vision_opencv-noetic/cv_bridge/build/devel/share/cv_bridge/cmake)
 21 set(OpenCV_DIR "/workspace/opencv-4.5.4/lib/cmake/opencv4")

vim vins-fusion-gpu-cv4-master/camera_models/CMakeLists.txt
 16 set(OpenCV_DIR "/workspace/opencv-4.5.4/lib/cmake/opencv4")

vim vins-fusion-gpu-cv4-master//loop_fusion/CMakeLists.txt
 9 set(cv_bridge_DIR /root/vision_opencv-noetic/cv_bridge/build/devel/share/cv_bridge/cmake)
 19 set(OpenCV_DIR "/workspace/opencv-4.5.4/lib/cmake/opencv4")

編譯:

root@ubuntu:/workspace/vins_fusion_gpu_catkin_ws# catkin_make -j8

4. 執行

更改配置引數, 加入:

use_gpu: 1
use_gpu_acc_flow: 1

rosrun vins vins_node src/VINS-Fusion/config/custom/xx.yaml

相關文章