OAK-D-Lite をROS Noeticで動かす

# はじめに

OAK-D-Liteが届いたのでROS Noeticで動かしてみた

以下はOAK-DのROSパッケージのリンク

https://github.com/luxonis/depthai-ros

https://github.com/luxonis/depthai-ros-examples

# 環境

OS : ubuntu20.04.03.LTS
ROS : Noeitc
OpenCV : 4.2.0

# ROS Noeticのインストール

まだROSをインストールしていない場合は公式の手順通りにインストールする。

http://wiki.ros.org/noetic/Installation/Ubuntu

https://qiita.com/porizou1/items/7c2c4b33126cfad05944



# パッケージのインストール

基本的に以下のREADME通り

https://github.com/luxonis/depthai-ros/blob/main/README.md


依存パッケージのインストール

```bash
sudo wget -qO- https://raw.githubusercontent.com/luxonis/depthai-ros/main/install_dependencies.sh | sudo bash
```

ワークスペースの作成

```bash
mkdir -p depthai_ws/src
```


ROSパッケージのインストール

```bash
cd depthai_ws/
wget https://raw.githubusercontent.com/luxonis/depthai-ros/main/underlay.repos
vcs import src < underlay.repos
rosdep install --from-paths src --ignore-src -r -y
source /opt/ros/noetic/setup.bash
catkin build 
source devel/setup.bash
```


# ROSノードの実行

## ステレオカメラの画像を使う

```bash
source ~/depthai_ws/devel/setup.bash
roslaunch depthai_examples stereo_node.launch camera_model:=OAK-D-LITE
```

rvizが起動し、カメラ画像、RobotModel、DeothCloudが表示される。

![rviz_screenshot_2022_03_27-15_03_27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/399606/3b2b6d72-aeb8-89b8-bf73-3b76e94737bd.png)


# RGB画像を使う

```bash
source ~/depthai_ws/devel/setup.bash
roslaunch depthai_examples rgb_publisher.launch camera_model:=OAK-D-LITE
```

`/rgb_publisher/color/image` , `/rgb_publisher/color/image/compressed`にカラー画像が出力される



# PointCloudを使う

```bash
source ~/depthai_ws/devel/setup.bash
roslaunch depthai_examples stereo_nodelet.launch camera_model:=OAK-D-LITE
```

実行するとrvizが起動する。
`/stereo_publisher/stereo/points`というトピックに`PointCloud2`型の点群が出力される。

![rviz_screenshot_2022_01_01-13_21_08.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/399606/bea27c65-0c24-88e3-bb89-477f378d3d35.png)

# YOLOv4で物体検出する

```bash
source ~/depthai_ws/devel/setup.bash
roslaunch depthai_examples yolov4_publisher.launch 
```

`/yolov4_publisher/color/yolov4_Spatial_detections`というトピックに物体検出結果が出力される。
以下で検出結果の確認。
画像はID：0 のpersonを検出した時の出力例

```bash
source ~/depthai_ws/devel/setup.bash 
rostopic echo /yolov4_publisher/color/yolov4_Spatial_detections
```

![Screenshot from 2022-01-01 20-30-24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/399606/2c82d930-8f8c-1327-e0b1-9fab83dfe475.png)

検出できる物体のクラスの一覧（depthai_example/ros1_src/yolov4_spatial_publisher.cpp 内の配列）

```bash:yolov4_spatial_publisher.cpp
const std::vector<std::string> label_map = {"person",         "bicycle",    "car",           "motorbike",     "aeroplane",   "bus",           "train",
             "truck",          "boat",       "traffic light", "fire hydrant",  "stop sign",   "parking meter", "bench",
             "bird",           "cat",        "dog",           "horse",         "sheep",       "cow",           "elephant",
             "bear",           "zebra",      "giraffe",       "backpack",      "umbrella",    "handbag",       "tie",
             "suitcase",       "frisbee",    "skis",          "snowboard",     "sports ball", "kite",          "baseball bat",
             "baseball glove", "skateboard", "surfboard",     "tennis racket", "bottle",      "wine glass",    "cup",
             "fork",           "knife",      "spoon",         "bowl",          "banana",      "apple",         "sandwich",
             "orange",         "broccoli",   "carrot",        "hot dog",       "pizza",       "donut",         "cake",
             "chair",          "sofa",       "pottedplant",   "bed",           "diningtable", "toilet",        "tvmonitor",
             "laptop",         "mouse",      "remote",        "keyboard",      "cell phone",  "microwave",     "oven",
             "toaster",        "sink",       "refrigerator",  "book",          "clock",       "vase",          "scissors",
             "teddy bear",     "hair drier", "toothbrush"};
```

# おわりに

OAK-D-Liteでもすべてのexampleを実行することができた。

# 参考

https://qiita.com/yo4hi6o/items/7d0dd6184d15d2366397


https://qiita.com/porizou1/items/800ad42c4cc39ee96af4

https://zenn.dev/karaage0703/scraps/79299ef4063626