이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Hi, How can I detect and track an object while its moving in a video and want to know its position?
조회 수: 15 (최근 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^^
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)