自适应背景更新
这个部分的方法参考您提供的论文的这个部分:
由于这里,人物的走动密度由的时候比较密集,有的时候比较稀疏,无法用传统的方法提取背景,所以这里的方法参考了如下的文献(代码包中我们提供了)
具体请看这几个章节。
对应的代码如下所示:
function back3 = func_getbackground(image,frames,T);
rows = size(image,1);
cols = size(image,2);
d(1:rows,1:cols,1) = image(1:rows,1:cols,1);
for k = 2:frames
d(1:rows,1:cols,k) = image(1:rows,1:cols,k) - image(1:rows,1:cols,k-1);
end
//以上就是求解图像的差分
CDM(1:rows,1:cols,2:frames) = d(1:rows,1:cols,2:frames);
CDM(abs(CDM) < T)=0;
CDM(abs(CDM) >= T)=255;
//求CDM值
m=0;
for i=1:rows
for j=1:cols
for k=2:frames
if CDM(i,j,k) == 0
m(k)=1;
end
if CDM(i,j,k) == 255
m(k)=rand(1);
end
end
position(i,j) = func_position(m);
end
end
//求解CDM中最大的连0的坐标
for i=1:rows
for j=1:cols
back3(i,j) =image(i,j,position(i,j));
end
end
//获得背景
第三步:当前图片与背景的差
这里求解差,并将得到的结果求二值图
第四步:形态学处理
function images3 = func_morpho(image);
%***************************************************************
%This function is used to remove the noise
rows = size(image,1);
cols = size(image,2);
%Remove noise by size judging
images3(1:rows,1:cols)=bwareaopen(image(1:rows,1:cols),40);
end
这里我们主要将视屏中的个别噪点去掉使画面更加’干净’;
第五步:边缘检测
function images = func_edgedetection(image);
%***************************************************************
%This function is used to find the edge in binary image
rows = size(image,1);
cols = size(image,2);
for i=2:rows-1
for j=2:cols-1
%Find boundary pixel
if image(i,j)==1 &&(image(i+1,j)==0||image(i-1,j)==0||image(i,j+1)==0||image(i,j-1)==0)
images(i,j)=255;
else
images(i,j)=0;
end
end
end
%Boundary of image
images(rows,:)=0;
images(:,cols)=0;
end
普通边间求解法
第六步:最后的运动跟踪效果
function [res,res2] = func_detect(iamges0,images,seq);
[r,c] = size(images);
res(:,:,1) = seq;
res(:,:,2) = seq;
res(:,:,3) = seq;
for i = 1:r
for j = 1:c
if images(i,j) == 255
res(i:i,j:j,1) = 255;
res(i:i,j:j,2) = 0;
res(i:i,j:j,3) = 0;
else
res(i,j,1) = seq(i,j);
res(i,j,2) = seq(i,j);
res(i,j,3) = seq(i,j);
end
end
end
[rows,cols] = size(iamges0);
for i = 1:rows
for j = 1:cols
if iamges0(i,j) == 1
tt = rand(1,1);
if tt > 0.4
res2(i:i,j:j,1) = 255;
res2(i:i,j:j,2) = 0;
res2(i:i,j:j,3) = 0;
else
res2(i,j,1) = seq(i,j);
res2(i,j,2) = seq(i,j);
res2(i,j,3) = seq(i,j);
end
else
res2(i,j,1) = seq(i,j);
res2(i,j,2) = seq(i,j);
res2(i,j,3) = seq(i,j);
end
end
end