現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Hi, How can I detect and track an object while its moving in a video and want to know its position?
12 ビュー (過去 30 日間)
古いコメントを表示
Hi, How can I detect and track an object while its moving in a video and want to know its position?
採用された回答
Image Analyst
2022 年 11 月 6 日
See my attached demo where I track a green Sharpie in a video.
16 件のコメント
Batuhan Istanbullu
2022 年 11 月 13 日
Thanks for the help!, but I just want to change my color to blue and in order to do that I need to change your parameters for green to blue; How I am able to do that ? I mean how can I find thresholds for blue at HSV? Do you mind helping me more ? cause if you will, it means a lot for my research at my MSc.
Image Analyst
2022 年 11 月 13 日
You can use the Color Thresholder app on the Apps tab of the tool ribbon to determine the thresholds for your image(s).
Batuhan Istanbullu
2022 年 11 月 14 日
I did change the HSV values to mine but I couldn't find any data related to this particular part in your code;
hsv = rgb2hsv(double(thisFrame));
hue=hsv(:,:,1);
sat=hsv(:,:,2);
val=hsv(:,:,3);
my new HSV values;
hThresholds = [0.969, 0.588];
sThresholds = [0.000, 0.386];
vThresholds = [0.959, 1.000];
Batuhan Istanbullu
2022 年 11 月 14 日
And also do I need these values for detecting an object during my recorded video?, or are these values only for saturation and other purposes?
Image Analyst
2022 年 11 月 14 日
If you're trying to find vividly colored items, then the sThreshold is wrong and the hThreshold is reversed. They should be
hThresholds = [0.588, 0.969];
sThresholds = [0.386, 1.000];
vThresholds = [0.959, 1.000];
ALso check the vThreshold because that looks awfully high.
Batuhan Istanbullu
2022 年 11 月 20 日
I will check it, but before checking I just want to show you this; I changed the video and hsv values of the desired thing that I want but I got this errors. I must say I don't need to have histogramic graphs and hue, saturation and value part. All I want is the exact position of the image by every time it moves. How may I implement some codes and change to what I want? Any help would means a lot to me
Batuhan Istanbullu
2022 年 11 月 20 日
and to answer your question or more than a question your advice I did check it with the color thresholder app and it gives me that data cause I want to find a whitee led light that has been placed on my finger in a video
Walter Roberson
2022 年 11 月 20 日
It looks to me as if the number of frames request was being applied to an empty video.
Batuhan Istanbullu
2022 年 11 月 20 日
% Demo to track green color. Finds and annotates centroid and bounding box of green blobs.
% Modify thresholds to detect different colors.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Specify input video file name.
folder = pwd;
% fullFileName = 'rhinos.avi';
% fullFileName = 'traffic.avi';
baseFileName = 'BlueLed.wmv';
fullFileName = fullfile(folder, baseFileName);
% Instantiate a video reader object for this video.
videoObject = VideoReader(fullFileName);
% Setup other parameters
numberOfFrames = videoObject.NumberOfFrame;
% Set HSV thresholds for the green sharpie in the demo video.
% Modify the thresholds to detect different colors.
hThresholds = [0.588, 0.969];
sThresholds = [0.386, 1.000];
vThresholds = [0.959, 1.000];
% Read one frame at a time, and find specified color.
for k = 1 : numberOfFrames
% Read one frame
thisFrame=read(videoObject,k);
hImage=subplot(3, 4, 1);
% Display it.
imshow(thisFrame);
axis on;
caption = sprintf('Original RGB image, frame #%d 0f %d', k, numberOfFrames);
title(caption, 'FontSize', fontSize);
drawnow;
hsv = rgb2hsv(double(thisFrame));
hue=hsv(:,:,1);
sat=hsv(:,:,2);
val=hsv(:,:,3);
if k == 1
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
hCheckbox = uicontrol('Style','checkbox',...
'Units', 'Normalized',...
'String', 'Finish Now',...
'Value',0,'Position', [.2 .96 .4 .05], ...
'FontSize', 14);
end
% Compute histograms for H, S, and V channels
% Let's compute and display the histogram.
binaryH = hue >= hThresholds(1) & hue <= hThresholds(2);
binaryS = sat >= sThresholds(1) & sat <= sThresholds(2);
binaryV = val >= vThresholds(1) & val <= vThresholds(2);
% Overall color mask is the AND of all the masks.
coloredMask = binaryH & binaryS & binaryV;
% Filter out small blobs.
coloredMask = bwareaopen(coloredMask, 500);
[labeledImage, numberOfRegions] = bwlabel(coloredMask);
if numberOfRegions >= 1
stats = regionprops(labeledImage, 'BoundingBox', 'Centroid');
% Delete old texts and rectangles
if exist('hRect', 'var')
delete(hRect);
end
if exist('hText', 'var')
delete(hText);
end
% Display the original image again.
subplot(3, 4, 5); % Switch to original image.
hImage=subplot(3, 4, 5);
imshow(thisFrame);
axis on;
hold on;
caption = sprintf('%d blobs found in frame #%d 0f %d', numberOfRegions, k, numberOfFrames);
title(caption, 'FontSize', fontSize);
drawnow;
%This is a loop to bound the colored objects in a rectangular box.
for r = 1 : numberOfRegions
% Find location for this blob.
thisBB = stats(r).BoundingBox;
thisCentroid = stats(r).Centroid;
hRect(r) = rectangle('Position', thisBB, 'EdgeColor', 'r', 'LineWidth', 2);
hSpot = plot(thisCentroid(1), thisCentroid(2), 'y+', 'MarkerSize', 10, 'LineWidth', 2)
hText(r) = text(thisBB(1), thisBB(2)-20, strcat('X: ', num2str(round(thisCentroid(1))), ' Y: ', num2str(round(thisCentroid(2)))));
set(hText(r), 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
hold off
drawnow;
end
% See if they want to bail out
if get(hCheckbox, 'Value')
% Finish now checkbox is checked.
msgbox('Done with demo.');
return;
end
end
msgbox('Done with demo.');
here is the code itself too^^
Walter Roberson
2022 年 11 月 20 日
I do not see a link to the video, and I do not see your current code?
Batuhan Istanbullu
2022 年 11 月 20 日
and this is picture of the video, not a whole video but a screenshot of it. I want to track that led light during video and that finger is moving
Walter Roberson
2022 年 11 月 20 日
That video is Microsoft ASF codec. That codec is not supported on MacOS. When I convert the video to m4v using VLC then the program runs without problem for me.
I suspect that your system is not reading the video properly.
I find some indications that historically those kinds of videos were supported by MATLAB on Windows, but that there were difficulties that the frame count could not be determined until the file had been completely read. I do not know if that is still the case.
Batuhan Istanbullu
2022 年 11 月 21 日
I will try to search any solutions to that problem if possible, thank you for your help and attention Walter.
Have a good day!
その他の回答 (1 件)
Walter Roberson
2022 年 11 月 6 日
If this is in the context of Driving (video is really a camera), see https://www.mathworks.com/help/driving/ref/multiobjecttracker.html
If this were in the context of multiple sensors then see https://www.mathworks.com/help/fusion/multi-object-trackers.html
参考
カテゴリ
Help Center および File Exchange で Tracking and Motion Estimation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)