readerobj = mmreader('viptrain.avi');
s=zeros(120,160);
d=zeros(120,160);
p=zeros(120,160);
q=zeros(120,160);
one=zeros(120,160);
two=zeros(120,160);
sl=read(readerobj,1);
dl=read(readerobj,1);
sl1=sl;
dl1=dl;
% for long periodic updation......
for k=0:0
for l=1:1:300
b=read(readerobj,(l+(k*50)));
b2=read(readerobj,(l+1+(k*50)));
b1=read(readerobj,1);
for i=1:120
for j=1:160
if((((b2(i,j)-b(i,j))<30) &&((b(i,j)-b2(i,j))==0))||(((b(i,j)-b2(i,j))<30) &&((b2(i,j)-b(i,j))==0))) %threshold ths for stable history map
s(i,j)=s(i,j)+1;
else
s(i,j)=0;
end
if((((b2(i,j)-b1(i,j))<30) &&((b1(i,j)-b2(i,j))==0))||(((b1(i,j)-b2(i,j))<30) &&((b2(i,j)-b1(i,j))==0)))
d(i,j)=0;
else
d(i,j)=d(i,j)+1;
end
end
end
end
for i=1:120
for j=1:160
if((s(i,j)>100) && (d(i,j)>100))
sl(i,j,1)=b2(i,j,1);
sl(i,j,2)=b2(i,j,2);
sl(i,j,3)=b2(i,j,3);
elseif((s(i,j)>100) && (d(i,j)==0))
sl(i,j,1)=sl1(i,j,1);
sl(i,j,2)=sl1(i,j,2);
sl(i,j,3)=sl1(i,j,3);
end
end
end
sl1=sl;
figure
image(sl)
end
u=sl;
v=u;
c1=read(readerobj,1);
for i=1:120
for j=1:160
if((((u(i,j)-c1(i,j))<30) &&((c1(i,j)-u(i,j))==0))||(((c1(i,j)-u(i,j))<30) &&((u(i,j)-c1(i,j))==0)))
p(i,j)=0;
else
p(i,j)=255;
end
end
end
figure
imshow(p);
% calculating boundary boxes
vn1=p;
SE = strel('square',5);
BW1=vn1;
BW2 = imerode(BW1,SE);
BW3 = imdilate(BW2,SE);
figure;
imshow(BW3)
Ifill = imfill(BW3,'holes');
figure;
imshow(Ifill)
as=BW3;
im=BW3;
s=size(im);
cog_x=0;cog_y=0;
total=1;
for i=1:s(1,1)
for j=1:s(1,2)
if im(i,j)==255 % 1 or 255
total=total+1;
cog_x=cog_x+i;
cog_y=cog_y+j;
end
end
end
cog_x_avg=cog_x/total;
cog_y_avg=cog_y/total;
cenx=ceil( cog_x_avg)
ceny=ceil( cog_y_avg)
xe1=cenx-10;
xe2=cenx+10;
ye1=ceny-10;
ye2=ceny+10;
su=BW3;
for j=ye1:ye2
su(xe1,j)=180;
su(xe2,j)=180;
end
for i=xe1:xe2
su(i,ye1)=180;
su(i,ye2)=180;
end
figure;
image(su);
vn1=r;
SE = strel('square',5);
BW1=r;
BW2 = imerode(BW1,SE);
BW3 = imdilate(BW2,SE);
figure;
imshow(BW3)
Ifill = imfill(BW3,'holes');
figure;
imshow(Ifill)
as1=BW3;
as2=as1-as;
vn1=as2;
SE = strel('square',5);
BW1=as2;
BW2 = imerode(BW1,SE);
BW3 = imdilate(BW2,SE);
figure;
imshow(BW3)
Ifill = imfill(BW3,'holes');
figure;
imshow(Ifill)
as3=BW3;
im=as3;
s=size(im);
cog_x=0;cog_y=0;
total=1;
for i=1:s(1,1)
for j=1:s(1,2)
if im(i,j)==255 % 1 or 255
total=total+1;
cog_x=cog_x+i;
cog_y=cog_y+j;
end
end
end
cog_x_avg=cog_x/total;
cog_y_avg=cog_y/total;
cenx=ceil( cog_x_avg)
ceny=ceil( cog_y_avg)
xe10=cenx-10;
xe20=cenx+10;
ye10=ceny-10;
ye20=ceny+10;
su=as3;
for j=ye10:ye20
su(xe10,j)=180;
su(xe20,j)=180;
end
for i=xe10:xe20
su(i,ye10)=180;
su(i,ye20)=180;
end
figure;
image(su);
readerobj = mmreader('C:\Users\Elcot\Desktop\MVI_6908.avi');
mr = uint8(zeros(120,160,3,785));
mov = avifile('markd.avi')
i=0;
for g=1:700
er=read(readerobj,g);
if(g>=300 && g<=625 && i==0)
for j=ye1:ye2
er(xe1,j,3)=255;
er(xe2,j,3)=255;
end
for i=xe1:xe2
er(i,ye1,3)=255;
er(i,ye2,3)=255;
end
% marked video
mr(:,:,:,g) = er;
mov = addframe(mov,er);
i=1;
elseif(g>=625 && i==0)
for j=ye10:ye20
er(xe10,j)=255;
er(xe20,j)=255;
end
mov = addframe(mov,er);
for i=xe10:xe20
er(i,ye10)=255;
er(i,ye20)=255;
end
mov = addframe(mov,er);
for j=ye1:ye2
er(xe1,j,3)=255;
er(xe2,j,3)=255;
end
mov = addframe(mov,er);
for i=xe1:xe2
er(i,ye1,3)=255;
er(i,ye2,3)=255;
end
mr(:,:,:,g) = er;
mov = addframe(mov,er);
i=1;
else
mr(:,:,:,g) = er;
mov = addframe(mov,er);
i=0;
end
end
mov = close(mov);