由于此视频是使用稳定的相机拍摄的,因此您可以轻松进行背景减法:
%// read the video:
reader = VideoReader('daria_walk.avi');
vid = {};
while hasFrame(reader)
vid{end+1} = im2single(readFrame(reader));
end
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4 );
%// estimate foreground as deviation from estimated background:
fIdx = 43; %// do it for frame 43
fg = sum( abs( vid{fIdx} - bg ), 3 ) > 0.25;
现在你可以看到结果:
figure;
subplot(131); imshow( bg );
subplot(132); imshow( vid{fIdx} );
subplot(133); imshow( fg );
结果