一、前言
Matlab自带的computer vision toolbox主要是toolbox里的vision模块,下面使用vision工具箱自带的混合高斯模型检测前景。
二、代码
%GMM前景检测
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 20);
videoReader = vision.VideoFileReader('Crowd-Activity-All.avi');
while ~isDone(videoReader)
frame = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frame);
subplot(1,2,1);
imshow(frame);
title('Video Frame');
subplot(1,2,2);
imshow(foreground);
title('Foreground');
pause(0.001);
end
三、结果