program for tracking the moving object in an video,by centroid method
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have made the program for tracking the moving object in an video,by centroid method, but after 44 frames an error is coming. I have located plus sign on the centroid, and it is appearing till frame 44 but after it an error is coming. Following is the error Subscript indices must be logical or real positive integers error in im(p,y) Following is my code
clc;
close all;
%read the first frame of video
vidObj=VideoReader('tank_human.avi');
% Create an axes
currAxes = axes;
% Read video frames until available
k=1;
while hasFrame(vidObj)&&(k<=100)
vidFrame = readFrame(vidObj);
image(vidFrame, 'Parent', currAxes);
currAxes.Visible = 'off';
pause(1/vidObj.FrameRate);
F=getframe;
%figure(2);
%imshow(F.cdata);
[F,map]=frame2im(F);
im=rgb2gray(F);
%figure(3);
%imshow(im);
im=double(im);
[row1,col1]=size(im);
if(k>18&&k<24)
n1=120;
else if(k>=24)
n1=140;
else
n1=115;
end
end
if true
% code
endn2=310+k;
%%Extract 64 x 64 subframe from 1st frame
row2=row1-n1;
col2=col1-n2;
subframe=zeros(100,100);
m1=1;
m2=1;
while m1<=100;
while m2<=100;
subframe(m1,m2)=im(row2,col2);
col2=col2+1;
m2=m2+1;
end
row2=row2+1;
m1=m1+1;
m2=1;
col2=col1-n2;
end
subframe1=subframe;
%figure(4);
%imshow(subframe1,[]);
int_sumx=0;
x_cent=0;
row3=row1-n1;
col3=col1-n2;
z1=row3;z2=col3;
while z1<=(row3+100)
while z2<=(col3+100)
x_cent=x_cent+(im(z1,z2)*z1);
int_sumx=int_sumx+im(z1,z2);
z2=z2+1;
end
z1=z1+1;
z2=col3;
end
x_int_cent=(x_cent/int_sumx);
int_sumy=0;
y_cent=0;
row3=row1-n1;
col3=col1-n2;
z1=row3;z2=col3;
while z1<=(col3+100)
while z2<(row3+100)
y_cent=y_cent+(im(z1,z2)*z2);
int_sumy=int_sumy+im(z1,z2);
z2=z2+1;
end
z1=z1+1;
z2=col3;
end
y_int_cent=(y_cent/int_sumy);
% superimpose '+' on target and encircle it %
x=floor(x_int_cent);
y=floor(y_int_cent);
%a=im(x,y);
for p=(x-2):1:(x+2)
im(p,y)=256;
end
for q=(y-2):1:(y+2)
im(x,q)=256;
end
figure(2);
imshow(im,[]);colormap(gray);
k=k+1
end
0 commentaires
Réponses (1)
Image Analyst
le 4 Mar 2017
Modifié(e) : Image Analyst
le 4 Mar 2017
Without your video file and more comments in your code, I'm not going to dive into that and debug it, especially when it's something you can do yourself. See http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
My guess is that either p or y is zero like the error message says. Or else they're fractional numbers. See the FAQ:
0 commentaires
Voir également
Catégories
En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!