matlab - 检测人脸,裁剪并将它们保存在不同的文件中
问题描述
我有图像数据(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
解决方案
推荐阅读
- twilio - Twilio 在队列中发送客户端呼叫所有代理,告诉他们呼叫者的姓名并将第一个与客户端连接
- python - (Python) 如何拟合 ValueError: Expected 2D array, got 1D array:
- php - WordPress页面背景
- node.js - collection.find.each 中的 socket.emit 问题
- bash - 需要在新的 Git 标签上运行一个“挂钩”(新拉标签的 Git 挂钩)
- python-3.x - 多线程中的诅咒包装器在退出后不会恢复屏幕
- r - 如何在R中按组在数据帧列中迭代地除以最后一个观察值,然后存储结果
- list - 从两个列表中创建元组
- javascript - 在 for 循环中向对象添加键值对
- vhdl - 在 VHDL 设计中是否推荐使用时钟?