?? tracking_changedetection.m
字號:
clear all
echo off
%fname='E:\目標跟蹤\目標跟蹤論文(2006年4月)\capture01.m1v';
fname='E:\目標跟蹤\目標跟蹤論文(2006年4月)\如心樓下.m1v';
back=zeros(288,352);
for k=1:50;
[R1 G1 B1]=mpgread(fname,k);
back = back+0.299.*R1 + 0.587.*G1 + 0.114*B1;
end
back=back./50;
[R1 G1 B1]=mpgread(fname,51);
%kuang_x_xia=90;kuang_x_sh=120;
%kuang_y_xia=30;kuang_y_sh=70;
RGB(:,:,1)=R1;
RGB(:,:,2)=G1;
RGB(:,:,3)=B1;
imshow(RGB)
%kuang_x_xia=160;kuang_x_sh=180;
%kuang_y_xia=40;kuang_y_sh=80;
I= 0.299.*R1 + 0.587.*G1 + 0.114*B1;
%[x,map]=gray2ind(I);
%mov(1)=im2frame(x,map);
%m1=abs(0.299.*R1 + 0.587.*G1 + 0.114*B1-back)>0.1;
%[x,map]=gray2ind(m1);
%movm(1)=im2frame(x,map);
%畫框
key=waitforbuttonpress;
cp1=get(gca,'CurrentPoint');
kuang_x_xia=cp1(1,2);kuang_y_xia=cp1(1,1);
key=waitforbuttonpress;
cp2=get(gca,'CurrentPoint');
kuang_x_sh=cp2(1,2);kuang_y_sh=cp2(1,1);
R1(kuang_x_xia:kuang_x_sh,kuang_y_xia)=1;
G1(kuang_x_xia:kuang_x_sh,kuang_y_xia)=0;
B1(kuang_x_xia:kuang_x_sh,kuang_y_xia)=0;
R1(kuang_x_xia:kuang_x_sh,kuang_y_sh)=1;
G1(kuang_x_xia:kuang_x_sh,kuang_y_sh)=0;
B1(kuang_x_xia:kuang_x_sh,kuang_y_sh)=0;
R1(kuang_x_xia,kuang_y_xia:kuang_y_sh)=1;
G1(kuang_x_xia,kuang_y_xia:kuang_y_sh)=0;
B1(kuang_x_xia,kuang_y_xia:kuang_y_sh)=0;
R1(kuang_x_sh,kuang_y_xia:kuang_y_sh)=1;
G1(kuang_x_sh,kuang_y_xia:kuang_y_sh)=0;
B1(kuang_x_sh,kuang_y_xia:kuang_y_sh)=0;
RGB(:,:,1)=R1;
RGB(:,:,2)=G1;
RGB(:,:,3)=B1;
imshow(RGB)
imwrite(RGB,'001.bmp')
for k=51:1000
[R G B]=mpgread(fname,k);
current= 0.299.*R + 0.587.*G + 0.114*B;
m1=abs(back-current)>0.1;
for m=1:288;
for n=1:352;
if(m1(m,n)==1)
back(m,n)=0.99*current(m,n)+0.01*back(m,n);
end
end
end
temp_x_sh=kuang_x_sh;
temp_x_xia=kuang_x_xia;
temp_y_sh=kuang_y_sh;
temp_y_xia=kuang_y_xia;
%計算新的框,搜索窗各左、右、上、下擴10個象素(嘗試8,5,3)
%沿水平方向的下限
T=0;
for i=kuang_x_xia-1:-1:kuang_x_xia-2;
if (i~=0)
for j=kuang_y_xia-2:kuang_y_sh+2;
if(j>0 && j<=352 && m1(i,j)==1)
T=T+1;
end
end
% if(T>(kuang_y_sh-kuang_y_xia))
if(T>1)
temp_x_xia=i;
end
end
end
if(T==0) %如果物體沒有向上運動,temp_x_xia應該向下擴展
T=0;
for i=kuang_x_xia+1:kuang_x_xia+2;
if(i<=288)
for j=kuang_y_xia-2:kuang_y_sh+2;
if(j>0 && j<=352 && m1(i,j)==1)
T=T+1;
end
end
if(T>1)
temp_x_xia=i;
break; %跳出for i的循環
end
end
end %for i
temp_x_xia=i;
end
T=0;
for i=kuang_x_sh+1:kuang_x_sh+2;
if(i<=288)
for j=kuang_y_xia-2:kuang_y_sh+2;
if(j>0 && j<=352 && m1(i,j)==1)
T=T+1;
end
end
%if(T>(kuang_y_sh-kuang_y_xia))
if(T>1)
temp_x_sh=i;
end
end
end
if(T==0) %如果物體沒有向下運動,temp_x_xia應該向上擴展
T=0;
for i=kuang_x_sh-1:-1:kuang_x_sh-2;
if(i>0 && i<=288)
for j=kuang_y_xia-2:kuang_y_sh+2;
if(j>0 && j<352 && m1(i,j)==1)
T=T+1;
end
end
if(T>1)
temp_x_sh=i;
break;
end
end
end %for i
temp_x_sh=i;
end
T=0;
for j=kuang_y_xia-1:-1:kuang_y_xia-2;
if(j>0 && j<=352)
for i=kuang_x_xia-2:kuang_x_sh+2;
if(i>0 && i<=288 && m1(i,j)==1)
T=T+1;
end
end
% if(T>(kuang_x_sh-kuang_x_xia))
if(T>1)
temp_y_xia=j;
end
end
end
if(T==0) %如果物體沒有向左運動,temp_x_xia應該向右擴展
T=0;
for j=kuang_y_xia+1:kuang_y_xia+2;
if(j>0 && j<=352)
for i=kuang_x_xia-2:kuang_x_sh+2;
if(i>0 && i<=288 && m1(i,j)==1)
T=T+1;
end
end
if(T>1)
temp_y_xia=j;
break;
end
end
end %for j
temp_y_xia=j;
end
T=0;
for j=kuang_y_sh+1:kuang_y_sh+2;
if(j>0 && j<=352)
for i=kuang_x_xia-2:kuang_x_sh+2;
if(i>0 && i<=288 && m1(i,j)==1)
T=T+1;
end
end
% if(T>(kuang_x_sh-kuang_x_xia))
if(T>1)
temp_y_sh=j;
end
end
end
if(T==0) %如果物體沒有向右運動,temp_x_xia應該向左擴展
T=0;
for j=kuang_y_sh-1:-1:kuang_y_sh-2;
if (j>0 && j<=352)
for i=kuang_x_xia-2:kuang_x_sh+2;
if(i>0 && i<=288 && m1(i,j)==1)
T=T+1;
end
end
if(T>1)
temp_y_xia=j;
break;
end
end
end
temp_y_sh=j;
end
if(temp_x_xia>temp_x_sh)
temp_x_xia=temp_x_sh;
end
if(temp_y_xia>temp_y_sh)
temp_y_xia=temp_y_sh;
end
R(temp_x_xia:temp_x_sh,temp_y_xia)=1;
G(temp_x_xia:temp_x_sh,temp_y_xia)=0;
B(temp_x_xia:temp_x_sh,temp_y_xia)=0;
R(temp_x_xia:temp_x_sh,temp_y_sh)=1;
G(temp_x_xia:temp_x_sh,temp_y_sh)=0;
B(temp_x_xia:temp_x_sh,temp_y_sh)=0;
R(temp_x_xia,temp_y_xia:temp_y_sh)=1;
G(temp_x_xia,temp_y_xia:temp_y_sh)=0;
B(temp_x_xia,temp_y_xia:temp_y_sh)=0;
R(temp_x_sh,temp_y_xia:temp_y_sh)=1;
G(temp_x_sh,temp_y_xia:temp_y_sh)=0;
B(temp_x_sh,temp_y_xia:temp_y_sh)=0;
%I= 0.299.*R + 0.587.*G + 0.114*B;
% [x,map]=gray2ind(I);
% mov(k-9)=im2frame(x,map);
% m1(temp_x_xia:temp_x_sh,temp_y_xia)=1;
% m1(temp_x_xia:temp_x_sh,temp_y_sh)=1;
% m1(temp_x_xia,temp_y_xia:temp_y_sh)=1;
% m1(temp_x_sh,temp_y_xia:temp_y_sh)=1;
% [x,map]=gray2ind(m1);
% movm(k-9)=im2frame(x,map);
RGB(:,:,1)=R;
RGB(:,:,2)=G;
RGB(:,:,3)=B;
imshow(RGB)
if (k-9) < 10
prefix = '00';
elseif (k-9) < 100
prefix = '0';
else
prefix = '';
end
imwrite(RGB,strcat(prefix,int2str(k-9),'.bmp'));
kuang_x_sh=temp_x_sh;
kuang_x_xia=temp_x_xia;
kuang_y_sh=temp_y_sh;
kuang_y_xia=temp_y_xia;
end
%mpgwrite(mov,map,'e:\eye\media\abs.mpg');
%mpgwrite(mov,map,'E:\目標跟蹤\目標跟蹤論文(2006年4月)\2_ChangeDetection.m1v');
%mpgwrite(movm,map,'E:\目標跟蹤\目標跟蹤論文(2006年4月)\2_ChangeDetection_m1.m1v');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -