原理
方法:叠加法
function [ output_args ] = sy1_2( input_args )
fileName='D:\workspace\Matlab workspace\数字图像处理\char2\char2_test\jmucorridor.avi';
obj=VideoReader(fileName);
numFrames=obj.NumberOfFrames;
f=read(obj,1);
subplot(2,2,1),imshow(f),title('第1帧');
[f,reverclass]=tofloat(f);
for i=600:1200
frame=read(obj,i);
[frame,reverclass]=tofloat(frame);
f=f+frame;
end
f=f/600;
subplot(2,2,2),imshow(f),title('计算结果');
fileName='D:\workspace\Matlab workspace\数字图像处理\char2\char2_test\q.avi';
obj=VideoReader(fileName);
numFrames=obj.NumberOfFrames;
f=read(obj,1);
subplot(2,2,3),imshow(f),title('第1帧');
[f,reverclass]=tofloat(f);
for i=1:100
frame=read(obj,i);
[frame,reverclass]=tofloat(frame);
f=f+frame;
end
f=f/100;
subplot(2,2,4),imshow(f),title('计算结果');
方法:前景+背景=全景 背景帧差法
%fileName='D:\workspace\Matlab workspace\数字图像处理\char2\char2_test\jmucorridor.avi';
fileName='D:\workspace\Matlab workspace\数字图像处理\char2\char2_test\jmucorridor.avi';
obj=VideoReader(fileName);
numFrames=obj.NumberOfFrames;
f=read(obj,1);
a=0.01;
for i=10:numFrames
frame=read(obj,i);
b=frame;
b=(1-a)*b+a*f;
o=frame-f;
ogray=f-b;
imshow(o);
end
subplot(2,2,1),imshow(f);
subplot(2,2,2),imshow(b);
subplot(2,2,3),imshow(o);
方法:直方图相减
function [ output_args ] = sy1_2( input_args )
fileName='D:\workspace\Matlab workspace\数字图像处理\char2\char2_test\jmucorridor.avi';
obj=VideoReader(fileName);
numFrames=obj.NumberOfFrames;
f=read(obj,1);
[f,reverclass]=tofloat(f);
fs=rgb2gray(f);
f2=read(obj,10);
[f2,reverclass]=tofloat(f2);
f2s=rgb2gray(f2);
subplot(3,2,1),imshow(fs);
subplot(3,2,2),imhist(fs),ylim('auto');
g=histeq(fs,256);
figure(1);
subplot(3,2,3),imshow(g);
subplot(3,2,4),imhist(g),ylim('auto');
subplot(3,2,5),imhist(fs-g),ylim('auto');
figure(2);
%fs=imread('Fig0228(a).tif');
%f2s=imread('Fig0233(a).tif');
subplot(3,2,1),imshow(fs);
subplot(3,2,2),imshow(f2s);
k=imhist(fs);
t=imhist(f2s);
n=length(k);
n(1,:)
d=0;
for i=1:n
di=k(i)-t(i);
d=d+di;
d=d/n;
u=1/2*(d);
q=sqrt(1/2*(d-u).^2);
Tmin=u*1.1;
Tmax=u+3.8*q;
end
d(1,:)
Tmax(1,:)
Tmin(1,:)
if d>=Tmin && d<=Tmax
subplot(3,2,6),imshow(fs);title('same');
else
error('different!');
end
实验结果:
1、
获取运动目标:
背景帧差法:
2、
获取视频背景(叠加法):
本文为原创。
转载请注明出处。