質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MATLAB

MATLABはMathWorksで開発された数値計算や数値の視覚化のための高水準の対話型プログラミング環境です。

Q&A

0回答

972閲覧

追跡プログラムでの対象物の座標の取得

mcmc

総合スコア4

MATLAB

MATLABはMathWorksで開発された数値計算や数値の視覚化のための高水準の対話型プログラミング環境です。

0グッド

0クリップ

投稿2019/09/23 04:47

編集2019/09/24 00:03

前提・実現したいこと

MATLABで動かした、赤色追跡のプログラムで取得した赤い物体の位置をリアルタイム(プログラム作動と同時に)で画面上での座標を知りたいです。(画面内に一つ)

発生している問題・エラーメッセージ

追跡プログラムは問題なく動きますが、追跡する画面しか出ません。
どのようにすれば、座標をプロットできますか?

該当のソースコード

% Capture the video frames using the videoinput function % You have to replace the resolution & your installed adaptor name. vid = videoinput( 'winvideo',1, 'YUY2_320x240'); % Set the properties of the video object set(vid, 'FramesPerTrigger', Inf); set(vid, 'ReturnedColorspace', 'rgb') vid.FrameGrabInterval = 5; %start the video aquisition here start(vid) % Set a loop that stop after 100 frames of aquisition while(vid.FramesAcquired<=200) % Get the snapshot of the current frame data = getsnapshot(vid); % Now to track red objects in real time % we have to subtract the red component % from the grayscale image to extract the red components in the image. diff_im = imsubtract(data(:,:,1), rgb2gray(data)); %Use a median filter to filter out noise diff_im = medfilt2(diff_im, [3 3]); % Convert the resulting grayscale image into a binary image. diff_im = im2bw(diff_im,0.18); % Remove all those pixels less than 300px diff_im = bwareaopen(diff_im,300); % Label all the connected components in the image. bw = bwlabel(diff_im, 8); % Here we do the image blob analysis. % We get a set of properties for each labeled region. stats = regionprops(bw, 'BoundingBox', 'Centroid'); % Display the image imshow(data) hold on %This is a loop to bound the red objects in a rectangular box. for object = 1:length(stats) bb = stats(object).BoundingBox; bc = stats(object).Centroid; rectangle('Position',bb,'EdgeColor','r','LineWidth',2) plot(bc(1),bc(2), '-m+') %a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2))))); %set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow'); end hold off end % Both the loops end here. % Stop the video aquisition. stop(vid); % Flush all the image data stored in the memory buffer. flushdata(vid); % Clear all variables clear all sprintf('%s','That was all about Image tracking, Guess that was pretty easy :) ')

補足情報(FW/ツールのバージョンなど)

参考にしたソースコード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問