---
# System prepended metadata

title: fisheyeFlattener on Jetson Orin Nano (imx219)

---

# 環境
* Ubuntu 20.04
* ROS Noetic
* ROS WorkSpace : `~/catkin_ws`
# 前置作業
* 安裝OpenCV 3.4 [Link](https://mailntustedutw-my.sharepoint.com/:b:/g/personal/m11102141_ms_ntust_edu_tw/EXoeNVS8u_1Gsu6bDSTU2HQBqUglAxOPgI07nMfgBQ7nDQ?e=d6HWUW)
* 安裝CVBridge : 
```bash=
cd ~/catkin_ws/src
sudo apt-get remove ros-noetic-cv-bridge
git clone https://github.com/ros-perception/vision_opencv.git
cd vision_opencv
git checkout noetic
cd cv_bridge
mkdir build
cd build
cmake ..
make
sudo make install
```
* 安裝ceres-solver [Link](http://ceres-solver.org/installation.html#linux) | [Download](https://github.com/ceres-solver/ceres-solver/releases/tag/2.1.0)
```bash=
sudo apt-get install libgoogle-glog-dev libgflags-dev libatlas-base-dev libeigen3-dev libsuitesparse-dev
wget https://github.com/ceres-solver/ceres-solver/archive/refs/tags/2.1.0.tar.gz
tar zxf 2.1.0.tar.gz
mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-2.1.0
make -j3
make install
```
* 安裝imx219 publisher : 
```bash=
cd ~/catkin_ws/src
git clone https://github.com/frakw/imx219.git
```

# 安裝
```bash=
sudo apt-get install libdw-dev libeigen3-dev
sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
cd ~/catkin_ws/src
git clone https://github.com/frakw/calib_image_saver.git
git clone https://github.com/frakw/camera_model.git
git clone https://github.com/frakw/fishEyeFlattener.git
cd ..
catkin_make
```
# 設定修改 (不需修改，保留預設即可)
## `calib_image_saver/launch/single_collect_image.launch`
* /image_input : 輸入的image topic
* image_path : 改成收集圖片要存放的資料夾路徑
* board_width : 水平棋盤格格數
* board_height : 垂直棋盤格格數
## `fishEyeFlattener/launch/flattener.launch` 
* cam_file : 相機的多項式係數yaml檔 (由camera_model所產生)
* inputTopic : 輸入的image topic
* outputTopicPrefix : 輸出image topic的prefix
* imgWidth : 輸入影像的寬度
# 執行
## fisheyeFlattener 魚眼攤平程式
```bash=
# new terminal
roscore
# new terminal
cd ~/catkin_ws/
source devel/setup.bash
rosrun imx219 dual_imx219.py
# new terminal
cd ~/catkin_ws/
source devel/setup.bash
roslaunch fisheye_flattener rgb1_flattener.launch
```
## calib_image_saver 校正圖片收集器
```bash=
# new terminal
roscore
# new terminal
cd ~/catkin_ws/
source devel/setup.bash
rosrun imx219 dual_imx219.py
# new terminal
cd ~/catkin_ws/
source devel/setup.bash
roslaunch calib_image_saver single_collect_image.launch
```
開始執行後會出現魚眼影像，將鏡頭對準棋盤圖片上下左右各角度進行收集 
[棋盤格PDF](https://mailntustedutw-my.sharepoint.com/:f:/g/personal/m11102141_ms_ntust_edu_tw/EhSieuOoIuZOmVDT1RKaB_0BL-VADay32MMxuQ0EEB0vfA?e=E3NY53)，預設使用8x6
## camera_model 相機校正多項式係數產生器
{input_path}為前面用calib_image_saver收集到的圖片存放路徑
{output_path}為存放camera_model生成圖片之路徑
```bash=
# new terminal
roscore
# new terminal
cd ~/catkin_ws/
source devel/setup.bash
rosrun camera_model Calibration --camera-name imx219 --input {input_path} -p IMG -e png -w 8 -h 6 --size 102.5 --camera-model myfisheye --opencv true --result_images_save_folder {output_path}
```
執行完畢後會生成`imx219_camera_calib.yaml`，內含攤平魚眼用的多項式係數。

## VINS-Fisheye
[VINS-Fisheye on Jetson Orin Nano (imx219)](https://hackmd.io/@frakw/S1WrwbBq3)