1. Problem description:
Research Status of Multi-target Tracking in the Environment Occlusion in Video Sequences
2. Part of the program:
clc;
clear;
close all;
vstream = mmreader('avi\11.avi');
ratio = 0.5;
imH = get(vstream,'Height')*ratio;
imW = get(vstream,'Width')*ratio;
nFrm = get(vstream,'NumberOfFrames');
for i=30:nFrm
n=i-1;
h=i-2;
m=read(vstream,i);%% read the image from S
m=rgb2gray(m);%% make the image M gray Degree of
m=medfilt2(m,[3,3]);% median filter
if i>=3
n = read(vstream,i-1);
n = rgb2gray(n);
h = read(vstream,i-2);
h = rgb2gray(h);
n = medfilt2(n,[3, 3]);
h = medfilt2(h,[3,3]);
q = im2double(m);%3.jpg% Convert the image array to double type
w = im2double(n);%2.jpg
g = im2double (h);%1.jpg
c = qw;
jx = qg;
th=10/255;
k=find(abs(c)>=th);
c(k)=1;
k=find(abs(c)<th);
c(k)=0;
c=bwareaopen(c ,15);% open operation, remove a small part
se90=strel('line',3,90);
se0=strel('line',3,0);
c=bwmorph(c,'close'); %Yes The above image is morphologically closed
c=imdilate(c,[se90,se0]);
c=bwmorph(c,'close');
c=bwareaopen(c,50);
k=find(abs(jx)>= th);
jx(k)=1;
k=find(abs(jx)<th);
jx(k)=0;
j=bwareaopen(j,15);
jx=bwmorph(jx,'close');% Perform morphological closed operation on the above image
jx=imdilate(jx,[se90,se0]);
jx=bwmorph(jx,'close');
jx=bwareaopen(jx,50);%除去小部分
c=c&jx;
c=imerode(c,[se90,se0]);
SE2 = strel('diamond', 6);
c=imdilate(c,SE2,'same'); %dilate
c = imresize(c,ratio);
figure(1);
subplot(221);imshow(c);
[Ls,ns] = bwlabel(c);
figure(1);
subplot(222);imshow(double(mean(Ls,3)),[]);
BW(1:size(c,1),1:size(c,2)) = 0;
for n=1:ns
[r,col] = find(Ls==n);
a1(n) = max(r);
a2(n) = min(r);
b1(n) = max(col);
b2(n) = min(col);
wx(n) = b1(n)-b2(n);
gx(n) = a1(n)-a2(n);
square(n) = wx(n)*gx(n);% area area
LL1 = size(r); the number of points in% area
if square( n)> 800% when the area is greater than a certain value
for ii = 1: LL1
BW(r(ii),col(ii)) = 1;% the midpoint of the area is white
end
end
end
figure(1);
subplot(223) ;imshow(BW);
[B,L,N,A] = bwboundaries(BW, 8,'noholes');
IMG_Org = read(vstream, i);
img = imresize(IMG_Org,ratio);
figure(1);
subplot(224);imshow(img);title(i);hold on;
disp(i);
nobjs(i) = size(B,1);
jj = 0;
nseg = i;
M(1:nobjs(i)) = 0;
Qw(i,1:nobjs(i)) = 0;
z = 1;
nn(i) = 0;
if nobjs(i)>1
for a=1:nobjs(i)-1
for j=1:nobjs(i)-a
x1=mean(B{a}(:,2));
x2=mean(B{j+a}(:,2));
dis=min(abs(max(B{j}(:,1))-min((B{a+j}(:,1)))),abs(max(B{a+j}(:,1))-min(B{j}(:,1))));
if (((x1<x2)&&(max(B{j}(:,2))>min(B{j+a}(:,2))))||((x1>x2)&&(min(B{j}(:,2))<max(B{j+a}(:,2)))))&&dis<500
M(a) = z;
M(a+j) = z;
L(a) = a;
L(a+j) = a;
z = z + 1;
nn(i) = nn(i) + 1;
end
end
end
end
% for j = 1:nobjs(i)
% plot(B{j}(:,2),B{j}(:,1),'y','LineWidth',2);hold on
% end
for j=1:nobjs(i)
%计算中心坐标
X_top(j) = max(B{j}(:,2))-3;
X_bot(j) = min(B{j}(:,2))+3;
Y_top(j) = max(B{j}(:,1))-3;
Y_bot(j) = min(B{j}(:,1))+3;
plot(X_bot(j):X_top(j),Y_bot(j),'g--','LineWidth',2); hold on;
plot(X_bot(j):X_top(j),Y_top(j), 'g--','LineWidth',2);hold on;
plot(X_bot(j),Y_bot(j):Y_top(j),'g--','LineWidth',2);hold on;
plot (X_top(j),Y_bot(j):Y_top(j),'g--','LineWidth',2); hold on;
end
% Perform head detection algorithm to distinguish different people
% for j=1:nobjs(i)-nn(i)
% %计算中心坐标
% X_top(j) = max(B{j}(:,2))-3;
% X_bot(j) = min(B{j}(:,2))+8;
% Y_top(j) = max(B{j}(:,1))-3;
% Y_bot(j) = min(B{j}(:,1))+3;
%
% X_center(nseg,j) = 0.5*(X_top(j) + X_bot(j));
% Y_center(nseg,j) = 0.5*(Y_top(j) + Y_bot(j));
% % X_center(nseg,j) =sum(B{j}(:,2))/size(B{j}(:,2),1);
% % Y_center(nseg,j) =sum(B{j}(:,1))/size(B{j}(:,1),1);
%
% plot(B{j}(:,2),B{j}(:,1),'y','LineWidth',2);hold on
%
% % plot(X_bot(j):X_top(j),Y_bot(j),'g--','LineWidth',2);hold on;
% % plot(X_bot(j):X_top(j),Y_top(j),'g--','LineWidth',2);hold on;
% % plot(X_bot(j),Y_bot(j):Y_top(j),'g--','LineWidth',2);hold on;
% % plot(X_top(j),Y_bot(j):Y_top(j),'g--','LineWidth',2);hold on;
% end
end
pause(0.5)
end
3. Simulation conclusion:
C-09