代码本身是在CSDN上下载其他老哥分享出来的包,用途是对图像进行处理,截出人脸部分并保存。根据自己的实际情况,我对主函数进行了一定少量修改,目前程序已经能正常跑通了。但是其中有很多被调用的.m文件,我并没有看明白处理过程,希望有好心的人指点一下。比如我下面列出的buildDetector从一开始参数输入我就不太理解,直接空括号输入,这个函数的处理过程是怎样的呀
主函数
currentPath = 'D:\Graduation project\T\';
image = imageDatastore(fullfile(currentPath),'IncludeSubfolders',true,'LabelSource','foldernames');
SavePath = 'D:\Graduation project\save\';
numImages = length(image.Files);
imagedata = readimage(image,2);
tt = image.Files(2);
tt1 = regexp(tt,'\','split');
cellLength = cellfun('length',tt1);
imagename = char(tt1{1}(1,cellLength));
save_path=[SavePath,imagename];
detector = buildDetector();
[bbox, bbimg, faces, bbfaces] = detectFaceParts(detector,imagedata,0);
for a=1:size(bbfaces,1)
imwrite(bbfaces{a},save_path);
end
其中被调用的buildDetector.m
function detector = buildDetector( thresholdFace, thresholdParts, stdsize )
if( nargin < 1 )
thresholdFace = 1;
end
if( nargin < 2 )
thresholdParts = 1;
end
if( nargin < 3 )
stdsize = 176;
end
nameDetector = {'LeftEye'; 'RightEye'; 'Mouth'; 'Nose'; };
mins = [[12 18]; [12 18]; [15 25]; [15 18]; ];
detector.stdsize = stdsize;
detector.detector = cell(5,1);
for k=1:4
minSize = int32([stdsize/5 stdsize/5]);
minSize = [max(minSize(1),mins(k,1)), max(minSize(2),mins(k,2))];
detector.detector{k} = vision.CascadeObjectDetector(char(nameDetector(k)), 'MergeThreshold', thresholdParts, 'MinSize', minSize);
end
detector.detector{5} = vision.CascadeObjectDetector('FrontalFaceCART', 'MergeThreshold', thresholdFace);
解读的非常好!