如何在MATLAB中像素化/模糊检测到的面部?

时间:2015-06-08 12:01:36

标签: matlab computer-vision matlab-cvst

我需要自动化视频中脸部的模糊/像素化。我是用MATLAB脚本完成的。我有R2013a版本,因此像readFrame和hasFrame这样的函数不起作用,因此奇怪的代码。代码当前使用框注释面部。我需要像素化这个区域,或者最好使用高斯模糊。我该怎么做?我无法找到任何相关内容。

%%MATLAB Code for R2013a (Code needs revision for newer versions) for boxing faces in a mp4 file file.mp4, saving it in AVI format as Detected_One
videoFReader = vision.VideoFileReader('file.mp4');
Videra=VideoReader('file.mp4');
%%Extracts original footage's num_frames and frame_rate
numFr=Videra.NumberOfFrames;
frmRa=Videra.FrameRate;
writerObj = VideoWriter('Detected_One');
%%Sets the written video's framerate as that of old
writerObj.FrameRate = frmRa;
open(writerObj);
faceDetector = vision.CascadeObjectDetector();

for i=1:numFr
    display(i);
    videoFrame = step(videoFReader);
    bbox            = step(faceDetector, videoFrame);
    videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');
    writeVideo(writerObj,videoOut);
close(figure);

end

release(videoFReader);
close(writerObj);

1 个答案:

答案 0 :(得分:1)

如果你google"高斯模糊Matlab"你将进入下一页:

http://uk.mathworks.com/help/images/ref/fspecial.html

你可以理解如何模糊:

H = fspecial('gaussian',[5 5],0.5);
blurred = imfilter(Image,H,'replicate');

如果您只想模糊图像的一部分,请提取该部分,将其模糊然后再次修补!