Skip to content

Commit

Permalink
[CRANE+ V2] カメラのキャリブレーション方法を追加 (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Kuwamai <[email protected]>
  • Loading branch information
YusukeKato and Kuwamai authored Aug 30, 2023
1 parent f897bff commit e74c9de
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions docs/cranev2/ros/camera-calibration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: カメラのキャリブレーション
robot: CRANE+ V2
---

# カメラのキャリブレーション
このページではCRANE+ V2の[カメラサンプル](https://github.com/rt-net/crane_plus/tree/master/crane_plus_examples#camera-examples)で使用するカメラのキャリブレーション方法について説明します。

カメラのキャリブレーションを行うと、カメラ画像の歪みやズレを補正することができます。

キャリブレーションが必要な例として、下図のようにカメラ画像とCRANE+ V2のモデルにズレが発生している場合などがあります。

![](../../img/cranev2/ros/before_calibration.png)

このズレが大きい場合、検出した物体位置もズレてしまうため、ピックアンドプレースが失敗する可能性があります。
キャリブレーションを行うと、このようなカメラ画像のズレを小さくすることができます。

## 使用機材 {: #requirements}

* 設置済みCRANE+ V2本体(Webカメラ搭載モデル)
* [製品マニュアル](https://rt-net.jp/products/cranev2/)を読んで設置済みの状態を前提としています
* ノートパソコン等のPC
* OS(**Ubuntu Desktop 22.04**)がインストール済みであることを前提としています
* ROS 2がインストール済みであることを前提としています
* [ROS 2のインストール手順](./install.md)を参照してください
* ROS 2用のパッケージがインストール済みであることを前提としています
* [ROS 2パッケージのインストール手順](./package-install.md)を参照してください
* キャリブレーション用のチェスボード
* [OpenCVのサンプル](https://github.com/opencv/opencv/blob/master/samples/data/chessboard.png)をA4サイズで印刷してください

## キャリブレーション用パッケージのインストール {: #install}
ノートパソコン等のPCに、キャリブレーションを行うためのROS 2パッケージをインストールします。

```bash
sudo apt install ros-humble-camera-calibration-parsers
sudo apt install ros-humble-camera-info-manager
sudo apt install ros-humble-launch-testing-ament-cmake
sudo apt install ros-humble-image-pipeline
```

## CRANE+ V2のカメラを起動 {: #launch-camera}
CRANE+ V2のカメラを起動します。
`port_name`はCRANE+ V2との通信に使用しているUSB通信ポート、`video_device`は使用するカメラのデバイス名を指定してください。
```bash
ros2 launch crane_plus_examples demo.launch.py port_name:=/dev/ttyUSB0 use_camera:=true video_device:=/dev/video0
```

## キャリブレーションの実行 {: #launch-calibration}
カメラのキャリブレーションを実行します。
`size`はチェスボードの交点の数を指定し、`square`はチェスボードの1マスの大きさ(単位はメートル)を指定してください。
```bash
ros2 run camera_calibration cameracalibrator --size 6x9 --square 0.022 --ros-args -r image:=/image_raw
```

![](../../img/cranev2/ros/camera_calibration_1.png)

カメラ映像が表示されたら、カメラの画角内でチェスボードを遠ざけたり、近づけたり、傾けたり、回転させたりなど動かします。

CALIBRATEボタンが緑色になったら押してしばらく待ちます。

![](../../img/cranev2/ros/camera_calibration_2.png)

その後、SAVEボタンを押すと、`/tmp`ディレクトリに`calibrationdata.tar.gz`ファイルが生成されます。

![](../../img/cranev2/ros/camera_calibration_3.png)

## パラメータファイルの配置 {: #replace-file}
パラメータファイル`ost.yaml``crane_plus/crane_plus_examples/config/camera_info.yaml`に配置します。
```bash
cd /tmp
tar -xvf calibrationdata.tar.gz
cp ost.yaml ~/ros2_ws/src/crane_plus/crane_plus_examples/config/camera_info.yaml
```

以上でCRANE+ V2のカメラのキャリブレーションは完了です。

パラメータファイルを配置した後に再びカメラを起動すると、カメラ画像とCRANE+ V2のモデルのズレが小さくなっていることが確認できます。

![](../../img/cranev2/ros/after_calibration.png)


## 参考
- [Camera Calibration — Navigation 2 1.0.0 documentation](https://navigation.ros.org/tutorials/docs/camera_calibration.html)
Binary file added docs/img/cranev2/ros/after_calibration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/cranev2/ros/before_calibration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/cranev2/ros/camera_calibration_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/cranev2/ros/camera_calibration_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/cranev2/ros/camera_calibration_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ nav:
- 2. ROS 2パッケージのインストール: cranev2/ros/package-install.md
- 3. ROS 2サンプルの実行(実機): cranev2/ros/samples.md
- 4. ROS 2サンプルの実行(シミュレータ) : cranev2/ros/simulator.md
- 5. カメラのキャリブレーション: cranev2/ros/camera-calibration.md
- 3. 関連リンク集: cranev2/others.md
- CRANE-X7:
- 1. 製品について: crane-x7/products.md
Expand Down

0 comments on commit e74c9de

Please sign in to comment.