I need some help in my code. I am trying to read the images from a folder and detect faces from then and save the cropped images in another folder. But while running the code it is not saving the cropped images into the folder properly. It's overwriting the images.
HER IS THE CODE
Folder = 'OUTPUT';FileList = dir(fullfile(Folder, '*.jpg'));for iFile = 1:numel(FileList)File = fullfile(Folder, FileList(iFile).name);I = imread(File);% figure(1),imshow(I);
FaceDetect = vision.CascadeObjectDetector; BB = step(FaceDetect,I);% figure(2),imshow(I);
for i = 1:size(BB,1)rectangle('Position',BB(i,:),'LineWidth',3,'LineStyle','-','EdgeColor','r');endfor i = 1:size(BB,1)J= imcrop(I,BB(i,:));M = imresize(J,[48 48]);imgray=rgb2gray(M);fname = sprintf('%06d.jpg',i);fpath = fullfile('Fdetected', fname);imwrite(imgray,fpath);endend
Best Answer