本記事でできること
想定シーン
ロボットをビジュアルフィードバック制御する
カメラを使ったロボットアームの制御方法を、ビジュアルフィードバック制御といいます。ここでは、ビジュアルフィードバック制御を使った自動化システムを開発する際に必要となる画像認識プログラムをまとめています。
円や点を描く
ビジュアルフィードバック制御における画像処理をする際に、認識したターゲット物体やロボットの注視領域を表示するために円を描きたい、という場合があります。対象舞台上の目標点と、ロボットの制御点を表示して、制御が収束していることを描画するなどの用途でも使用します。本記事では、円(circle)と中実円(中が詰まった円)を描画するプログラムを掲載します。
実行環境
- OS:Ubuntu 22.04 LTS
- 言語:C++
- クルーボ:v5.1.0
クルーボについて
ロボットアプリケーション開発には、株式会社チトセロボティクスのロボット制御ソフトウェア「クルーボ」を使用します。本記事のプログラムは、クルーボがインストールされた制御コンピュータ上で動作します。
- クルーボの製品サイト:https://chitose-robotics.com/product
プログラム抜粋
cv::Mat draw_circle(
const cv::Mat image, const cv::Point center, const float radius, const cv::Scalar color, const int thickness) {
cv::Mat drawed_image = image.clone();
cv::circle(drawed_image, center, static_cast<int>(radius), color, thickness, CV_MSA);
return drawed_image;
}
cv::Mat draw_dot(const cv::Mat image, const cv::Point center, const float radius, const cv::Scalar color) {
cv::Mat drawed_image = image.clone();
const int thickness = -1;
cv::circle(drawed_image, center, static_cast<int>(radius), color, thickness, CV_MSA);
return drawed_image;
}
全体プログラム
#include <iostream>
#include <opencv2/opencv.hpp>
cv::Mat draw_circle(
const cv::Mat image, const cv::Point center, const float radius, const cv::Scalar color, const int thickness) {
cv::Mat drawed_image = image.clone();
cv::circle(drawed_image, center, static_cast<int>(radius), color, thickness, CV_MSA);
return drawed_image;
}
cv::Mat draw_dot(const cv::Mat image, const cv::Point center, const float radius, const cv::Scalar color) {
cv::Mat drawed_image = image.clone();
const int thickness = -1;
cv::circle(drawed_image, center, static_cast<int>(radius), color, thickness, CV_MSA);
return drawed_image;
}
int main(void) {
const cv::Size image_size(1280, 960);
const cv::Mat black_image = cv::Mat::zeros(image_size.height, image_size.width, CV_8UC3);
cv::Mat drawed_image = black_image.clone();
const cv::Point circle_center(200, 300);
const float circle_radius = 70.f;
drawed_image = draw_circle(drawed_image, circle_center, circle_radius, cv::Scalar(0, 0, 255), 5);
const cv::Point dot_center(700, 500);
const float dot_radius = 40.f;
drawed_image = draw_dot(drawed_image, dot_center, dot_radius, cv::Scalar(255, 0, 0));
cv::imshow("drawed_image", drawed_image);
cv::waitKey(0);
}
おわりに
人手作業をロボットアームで自動化するために、カメラを使ったロボット制御=ビジュアルフィードバック制御が大切です。
ロボット制御用の画像認識でも中身のひとつひとつはシンプルなので、要素に分解して解説していきたいと思います。