Skip to content

color_detectionサンプルの追加#183

Open
KuraZuzu wants to merge 22 commits into
ros2from
feature/color_detection
Open

color_detectionサンプルの追加#183
KuraZuzu wants to merge 22 commits into
ros2from
feature/color_detection

Conversation

@KuraZuzu

@KuraZuzu KuraZuzu commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What does this implement/fix?

color_detectionサンプルを追加します。

crane_x7_roscolor_detectionサンプルをベースに実装しています。

移植に加えて、Sciurus17向けに以下の変更・修正を行っています。

  • sciurus17_examples/src/color_detection_2d.cpp

    • 既存の2Dトラッキング用 color_detection コンポーネントを color_detection_2d にリネームしました。
    • C++クラス名は ColorDetection2D に変更しています。
    • head_camera_tracking.launch.py / chest_camera_tracking.launch.py の component 名・plugin 名も更新しています。
    • 処理内容は変更していません。
  • sciurus17_examples/src/color_detection.cpp

    • C++版 color_detection として、 Sciurus17 のカメラ構成に合わせて調整しました。
    • 入力トピックを /head_camera/color/image_raw/head_camera/aligned_depth_to_color/image_raw/head_camera/color/camera_info に変更しています。
    • 検出結果は target_0 の TF として配信します。
    • Gazeboと実機でのRealsenseのエンコードデータが違うため、深度画像の encoding として 16UC132FC1 の両方に対応しています。
    • HSV変換時に共有されたROS画像バッファを書き換えないよう、画像をコピーして処理するようにしました。
    • TFの姿勢 quaternion に恒等回転 w=1.0 を明示しました。
    • cv::moments() の名前空間を明示しました。
    • 深度画像アクセス時の座標変換を明示的な static_cast<int> にしました。
  • sciurus17_examples/src/pick_and_place_tf.cpp

    • pick_and_place_tf.cpp を実機/Gazeboでの動作に合わせて調整しました。
    • 把持対象のZ方向下限が0.03程度となって青色キューブが把持対象外となってしまうため、0.04 から 0.02 に緩和しています。
  • sciurus17_examples_py/sciurus17_examples_py/color_detection.py

    • Python版の color_detection サンプルとして追加しました。
    • C++版と同様にRGB画像・深度画像・CameraInfoを同期して使用します。
    • 16UC1 / 32FC1 の深度画像 encoding に対応しています。
    • 検出結果を target_0 の TF として配信します。
    • TFの姿勢 quaternion に恒等回転 w=1.0 を明示しています。
  • sciurus17_examples_py/sciurus17_examples_py/pick_and_place_tf.py

    • Python版の pick_and_place_tf.py を追加しました。
    • Sciurus17の左右腕・腰・左右グリッパ・首のMoveIt groupに合わせています。
    • 物体位置のY座標に応じて左右の腕を切り替えるようにしています。
    • グリッパの開始状態が可動範囲外にならないよう、現在角度を範囲内に丸める処理を追加しています。
  • その他

    • C++版/Python版それぞれの launch、依存関係、README を更新しました。
    • camera_example.launch.py から color_detection を起動できるようにしました。
    • image_transportmessage_filtersimage_geometrytf2_roscv_bridge など必要な依存関係を追加しています。
    • README に color_detection の実行方法と、配信される TF frame の説明を追記しました。

Does this close any currently open issues?

しません。

How has this been tested?

実機とGazeboの両方で動作を確認しました。

  1. Sciurus17を起動する
# 実機
$ ros2 launch sciurus17_examples demo.launch.py
# Gazebo
$ ros2 launch sciurus17_gazebo sciurus17_with_blue_cube.launch.py
  1. color_detectioサンプルを実行する
# C++版サンプル
$ ros2 launch sciurus17_examples camera_example.launch.py example:='color_detection'
# Python版サンプル
$ ros2 launch sciurus17_examples_py camera_example.launch.py example:='color_detection'

Any other comments?

なし

Checklists

@KuraZuzu KuraZuzu self-assigned this Jun 22, 2026
@KuraZuzu KuraZuzu added the Type: Feature New Feature label Jun 22, 2026
@KuraZuzu KuraZuzu requested a review from Copilot June 22, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Sciurus17向けに、特定色(デフォルト青)の物体を深度画像込みで検出し、TF(target_0)として配信してピッキングにつなぐ color_detection サンプル(C++/Python)を追加するPRです。既存の2D版 color_detection コンポーネントは color_detection_2d にリネームし、追従系launchから参照する構成に整理しています。

Changes:

  • C++: 深度+CameraInfoを同期して3D位置を算出しTF配信する color_detection 実行ファイルを追加
  • C++: 既存2D検出コンポーネントを color_detection_2d に改名し、関連launchを更新
  • Python: color_detection と、それに対応する pick_and_place_tf とカメラ例launchを追加

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
sciurus17_examples/src/color_detection.cpp 深度/CameraInfo同期で3D位置を算出しTF配信する新しい実行ファイルノードを実装
sciurus17_examples/src/color_detection_2d.cpp 既存2D検出を ColorDetection2d としてコンポーネント化
sciurus17_examples/include/sciurus17_examples/color_detection_2d.hpp ColorDetection2d の新規ヘッダ/ガード名更新
sciurus17_examples/CMakeLists.txt color_detection_2d をコンポーネント登録、color_detection を実行ファイルとして追加、依存追加
sciurus17_examples/package.xml image_transport/message_filters/tf2_ros 依存追加
sciurus17_examples/README.md color_detection サンプル説明を追加
sciurus17_examples/launch/head_camera_tracking.launch.py 参照コンポーネントを color_detection_2d に更新
sciurus17_examples/launch/chest_camera_tracking.launch.py 参照コンポーネントを color_detection_2d に更新
sciurus17_examples/launch/example.launch.py 例示リスト文言を更新
sciurus17_examples/launch/camera_example.launch.py color_detection を例示リストに追加
sciurus17_examples_py/setup.py pick_and_place_tfcolor_detection エントリポイント追加
sciurus17_examples_py/sciurus17_examples_py/pick_and_place_tf.py TFターゲットを見てピック&プレースするノードを新規追加
sciurus17_examples_py/sciurus17_examples_py/color_detection.py Python版の深度同期・3D算出・TF配信ノードを新規追加
sciurus17_examples_py/launch/camera_example.launch.py Python版のカメラ例launchを新規追加
sciurus17_examples_py/package.xml Pythonサンプル実行に必要な依存を追加
sciurus17_examples_py/README.md Python版 color_detection サンプル説明を追加

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sciurus17_examples/src/color_detection.cpp
Comment thread sciurus17_examples/src/color_detection.cpp
Comment thread sciurus17_examples/src/color_detection.cpp
Comment thread sciurus17_examples/src/color_detection.cpp Outdated
Comment thread sciurus17_examples/src/color_detection_2d.cpp
Comment thread sciurus17_examples_py/sciurus17_examples_py/color_detection.py Outdated
Comment thread sciurus17_examples_py/sciurus17_examples_py/color_detection.py
Comment thread sciurus17_examples/README.md Outdated
Comment thread sciurus17_examples_py/README.md Outdated
Comment thread sciurus17_examples/launch/camera_example.launch.py
KuraZuzu and others added 14 commits June 22, 2026 17:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@KuraZuzu KuraZuzu requested a review from Kuwamai June 23, 2026 06:21
@KuraZuzu

Copy link
Copy Markdown
Contributor Author

@Kuwamai レビューをお願いします。

@KuraZuzu KuraZuzu marked this pull request as ready for review June 23, 2026 06:29

@Kuwamai Kuwamai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KuraZuzu
取り急ぎドキュメントについてコメントしました。
実装について後ほど確認します 🙇

特定の色の物体を検出して掴むコード例です。

- デフォルトでは青い物体の位置をtfのフレームとして配信します。
- `target_0`は、カメラ画像の`frame_id`を親フレームとするtfフレームとして配信します。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この文章では配信するフレーム名について説明してほしいです。
親フレームについてはユーザーがサンプルを使う上で影響しないと思うので、言及しなくて大丈夫です。

@Kuwamai Kuwamai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KuraZuzu コードについてもコメントしました 🙇

Comment on lines +100 to +110
cv_depth = self.bridge.imgmsg_to_cv2(depth_msg, desired_encoding=depth_msg.encoding)

# カメラから把持対象物の表面までの距離
depth = cv_depth[int(point[1]), int(point[0])]
if depth_msg.encoding == '16UC1':
front_distance = float(depth) / 1000.0
elif depth_msg.encoding == '32FC1':
front_distance = float(depth)
else:
self.get_logger().warn(f'Unsupported depth encoding: {depth_msg.encoding}')
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この部分の実装の背景が知りたいです。
X7の実装では動作しませんでしたか?

@KuraZuzu KuraZuzu Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X7の実装のまま動作させたところ、実機では動作したものの、Gazebo上では動作しませんでした。
実機とGazeboでRealsenseのエンコード方式が違っていたため、ひとまずここのサンプル上の条件分岐で対応としたという背景です。

Comment on lines +151 to +165
// 深度画像アクセス用に小数座標を整数インデックスに変換
const cv::Point point_int(static_cast<int>(point.x), static_cast<int>(point.y));

// エンコーディングの違いによる深度値の取得方法の違いに対応
if (depth_msg->encoding == "16UC1") {
front_distance = cv_depth->image.at<uint16_t>(point_int) / 1000.0;
} else if (depth_msg->encoding == "32FC1") {
front_distance = cv_depth->image.at<float>(point_int);
} else {
RCLCPP_WARN(
this->get_logger(),
"Unsupported depth encoding: %s",
depth_msg->encoding.c_str());
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python版にコメントしてしまいましたが、どうようにこちらの意図も知りたいです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants