How to track the object using centroid ?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
채택된 답변
Walter Roberson
2013년 2월 19일
0 개 추천
regionprops() with the Centroid option.
You may need to convert the image to grayscale or binary first.
댓글 수: 13
aarthi ramasamy
2013년 2월 19일
편집: aarthi ramasamy
2013년 2월 19일
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.
Walter Roberson
2013년 2월 19일
편집: Walter Roberson
2013년 2월 19일
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.
Image Analyst
2015년 5월 13일
suppy ask your own question and I will supply my demo program that tracks a green object in a video.
Thomas Koelen
2015년 5월 13일
Suppy posted this in 2013 Image Analyst:P
Image Analyst
2015년 5월 13일
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)
