How to track the object using centroid ?
显示 更早的评论
I need to track the object in a video using centroid. By calculating the centroid of the object in different frames, I'll be able to track the object and get the count. I'm new to matlab and guide me in completeing the task
采纳的回答
regionprops() with the Centroid option.
You may need to convert the image to grayscale or binary first.
13 个评论
I have already converted it to binary image but the centroid portion is alone the problem here.
clc
clear all
n=0;
% Read movie
SF = 1; %Starting Frame
MV = mmreader('r2.avi'); %To read Movie
EF = MV.NumberofFrames ; %Ending Frame
img = read(MV,1); %reading particular frame
A = double(rgb2gray(img)); %motion vector works on Gray Image formate
[height width] = size(A); %Movie size?
% motion estimation
h1 = figure(1);
for f = SF: EF %Frame from SF To EF
B = A;
img = read(MV,f);
A = double(rgb2gray(img));
%Foreground Detection
thresh=11;
fr_diff = abs(A-B);
for j = 1:width
for k = 1:height
if (fr_diff(k,j)>thresh)
fg(k,j) = A(k,j);
else
fg(k,j) = 0;
end
end
end
subplot(2,2,1) , imagesc(img), title (['Orignal Sequence Frame#',int2str(f)]);
subplot(2,2,2) , imshow(mat2gray(A)), title ('Previous Frame');
subplot(2,2,3) , imshow(mat2gray(B)), title ('Next Frame');
sd=imadjust(fg);
level=graythresh(sd);
m=imnoise(sd,'gaussian',0,0.025);
k=wiener2(m,[5,5]);
bw=im2bw(k,level);
bw2 = bwareaopen(bw, 20, 8);
b1= imdilate(bw2, ones(1, 1, 5));
b2=imfill(b1,'holes');
% [labeled,numObjects] = bwlabel(bw,4);
% n=n+numObjects;
subplot(2,2,4) , imagesc(b1), title (['Foreground #',n]);
hold off;
%pause (.1);
% saveas(h1,strcat('Result-Paris-',num2str(f)),'jpg');
end
disp(n);
The above stated is my code. I don't know how to proceed further. My objective is to track the different objects and count it. I terribly need the guidance/code.
At the point where you have the commented bwlabel,
[labeled, numObjects] = bwlabel(b2, 4);
blobinfo = regionprops(labeled, 'Centroid');
now blobinfo(1).Centroid is the first centroid
% Extract all centroids for all blobs in a 1D list.
allBlobCentroids = [blobinfo.Centroid];
% From that list, extract out the x and y coordinates of the centroids.
centroidsX = allBlobCentroids(1:2:end-1);
centroidsY = allBlobCentroids(2:2:end);
Alternately,
allBlobCentrods = vertcat(blobinfo.Centroid);
would produce a numObjects x 2 array, first column x, second column y.
Thanks for your guidance Mr.Roberson . How to track the object using this centroid? I can clearly get the centroid of the objects in the different frames but applying this for tracking makes a problem here. What if there are two objects present in a single frame itself?
More than one object present in a single frame must be expected for your application.
When objects are sufficiently separated and exist separated for multiple frames, you can form a velocity estimate by associating the updated centroid positions with the nearest previous centroid position. Then when the objects come close together, instead of necessarily updating with the nearest previous centroid, you could do a position prediction based upon the velocities in order to try to figure out which of the close objects came from where.
Mr.Roberson,I can get your idea but coding seems to be difficult part here. Do you mind giving me the code? It will be of great use to us like beginners. Kindly help us
Yes, I do mind giving you the code, as what you are asking for is a common homework project for computer courses.
Thanks Mr. Roberson for your kind replies
hi sir.. i am very much new to matlab.. i need the code for moving object tracking and its velocity determination.
suppy ask your own question and I will supply my demo program that tracks a green object in a video.
Suppy posted this in 2013 Image Analyst:P
Oh - didn't notice. For some reason this showed up on the page of 50 most current postings. Sometimes that can happen if someone (like a spammer) replied and then it got deleted - it will show up on the current list even though the posting that got it there has now been deleted.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
另请参阅
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)
