J.K*_*.K. 4 matlab image-processing video-processing computer-vision matlab-cvst
我有一个.avi文件(取自作为时空形状的动作 - 分类数据集),我从中提取了.png格式的帧.现在,我想使用Matlab从这些图像进行前景检测.
我见过一个使用的代码vision.ForegroundDetector(),但它适用于视频文件.
所以,如果有人能给我代码前景检测图像,那么我会非常感激.
这是一个框架的示例:
由于此视频是使用稳定的相机拍摄的,因此您可以轻松进行背景减法:
%// 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;
Run Code Online (Sandbox Code Playgroud)
现在你可以看到结果:
figure;
subplot(131); imshow( bg );
subplot(132); imshow( vid{fIdx} );
subplot(133); imshow( fg );
Run Code Online (Sandbox Code Playgroud)