---
# System prepended metadata

title: VINS FISHEYE安裝
tags: [工研院]

---

## 教學文件
[安裝步驟文件下載](https://mailntustedutw-my.sharepoint.com/:f:/g/personal/b10615058_ms_ntust_edu_tw/EswC9HC_K4lAqhUCEX9_faQBuqQsJ1mp1sJxxCBSTXLQVA?e=oH3Vg7)

## 環境安裝
安裝 cudatoolkit & ros-noetic
### cuda
- https://developer.nvidia.com/cuda-toolkit-archive
- 裝完重開機
### ros-noetic
- 安裝教學
    - http://wiki.ros.org/noetic/Installation/Ubuntu
    - 安裝 `sudo apt install ros-noetic-ros-base`
        - 安裝desktop會自動安裝opencv4，因此安裝base再逐步安裝缺失項
        - 手動安裝 `sudo apt-get install qt5-default ros-noetic-tf2* ros-noetic-rviz`
- 創建資料夾catkin/src 並catkin_make
    ```
    echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
    echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    ```
    
## 安裝opencv 3.4.10
- 手動下載 opencv & contrib
    - https://github.com/opencv/opencv/releases/tag/3.4.10
    - https://github.com/opencv/opencv_contrib/releases/tag/3.4.10
- 照著說明文件安裝 (相依套件)
```
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
```
- cmake指令參考以下
    - OPENCV_EXTRA_MODULES_PATH換成contrib路徑
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/opt \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D WITH_CUDA=ON \
-D WITH_TBB=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_GENERATION=Auto \
-D WITH_V4L=ON \
-D WITH_OPENGL=ON \
-D WITH_QT=ON \
-D WITH_CUBLAS=1 \
-D BUILD_EXAMPLES=ON ..
```
- 常見編譯問題
        - https://www.cnblogs.com/geoffreyone/p/15040907.html

## boost
- 手動編譯 1.8.2
- 使用 1.7.5以下會報錯
- https://linux.how2shout.com/how-to-install-boost-c-on-ubuntu-20-04-or-22-04/
- 指定python3 (預設為2)
    - `./bootstrap.sh --prefix=/usr/ --with-python=/usr/bin/python3`

## cv bridge
- 照著說明文件安裝
- 下載到catkin_ws/src
- 修改cmakelists.txt後 catkin_make
- 照著說明文件 make & make install

## libsgm
- 升級 cmake
    - https://cmake.org/install/
- libsgm
    - https://github.com/fixstars/libSGM
- `CMakeLists.txt`
    - 將兩個option設置為ON，編譯vins會用到
    - 在project下方find_package指定cv 3，否則會指向cv 4
    - ![](https://hackmd.io/_uploads/BJ8-g9t5h.png)



## ceres
- 照著說明文件安裝
- 注意更改 `CMakeLists.txt` 否則編譯vins會失敗
![](https://hackmd.io/_uploads/ryPOhVPc3.png =500x)

## vins
- 照著說明文件安裝
- 修改`VINS-Fisheye/vins_estimator/CMakeLists.txt`
    - `set(ENABLE_BACKWARD false)`
    - `set(DETECT_CUDA true)` (cuda版本)
- 版本
    - 最新版
        - `git clone https://github.com/xuhao1/VINS-Fisheye`
        - 修改 `vins_estimator/src/featureTracker/feature_tracker_pinhole.hpp`
        - 將以下程式段落從`feature_tracker_pinhole.cpp`剪下貼到`feature_tracker_pinhole.hpp` 
          ![](https://hackmd.io/_uploads/ryvrCyuc3.png)
         - 在`vins_estimator/launch/fisheye.launch`加入第五行`<node pkg="nodelet" type="nodelet" name="$(arg manager)" args="manager" output="screen" />`
           ![](https://hackmd.io/_uploads/ryPc0MPs2.png)
        - 在`config/fisheye_ptgrey_n3/fisheye_cuda.yaml`的show_track設0，否則會卡在drawTrackFisheye()

    - 直接下載1.0
        - https://github.com/xuhao1/VINS-Fisheye/releases/tag/1.0
        - 解壓縮到catkin_ws/src
        - 修改 `VINS-Fisheye/camera_models/CMakeLists.txt`
            - 照以下更改 否則link ceres會報錯
            - ![](https://hackmd.io/_uploads/HJssLdYc3.png)
            - `set(CMAKE_CXX_STANDARD 11)`


    


## bag
```bash=
# new terminal
roslaunch vins fisheye.launch
# new terminal
roslaunch vins vins_rviz.launch
# new terminal
rosbag play fisheye_vins_2020-01-30-10-38-14.bag -s 12 --clock
```

