首页 > 解决方案 > 检测人脸,裁剪并将它们保存在不同的文件中

问题描述

我有图像数据(40 人),我试图检测每张图像中的人脸,裁剪它并将其保存在另一个文件中。我为此使用 MATLAB,但它不起作用。

错误:无法打开文件“C:\Users\mstfy\Desktop\Matlab\alex\newdata\cropped\”进行写入。您可能没有写入权限。

我认为我的for循环有问题。

location = 'C:\Users\mstfy\Desktop\Matlab\alex\newdata\*.jpg';
croppedimg = 'C:\Users\mstfy\Desktop\Matlab\alex\newdata\cropped\';
imds = imageDatastore ( 'C:\Users\mstfy\Desktop\Matlab\alex\newdata' , ...
    'IncludeSubfolders' , true, ...
    'LabelSource' , 'foldernames' );
idx = randperm (numel (imds.Files), 16);
j = 1;
figure
for t = 1: 16
    img = readimage (imds, idx (t));
    FaceDetect = vision.CascadeObjectDetector; 
    FaceDetect.MergeThreshold = 7;
    BB = step (FaceDetect, img);  
    for i = 1: size (BB, 1)     
      rectangle ( 'Position' , BB (i, :), 'LineWidth' , 3, 'LineStyle' , '-' , 'EdgeColor' , 'r' );
    end 
    for i = 1: size (BB, 1)
      J = imcrop (img, BB (i, :)); 
      figure (3);
      subplot (6, 6, i);
      imshow (J); 
      j = j + 1;
      imwrite (J,croppedimg,'jpg' )
    end
end

标签: matlabimage-processingface-detectioncascade-classifier

解决方案


推荐阅读