I have directory, there are many images in this directory, I want to detect the face from images, and create the directories of image name store only the faces on that directory. How to do this, kindly help me

1 view (last 30 days)
myDir = 'C:\myImages\';
this is the name of directory which contains many images. i want to detect the faces from images and want to crop the face from image and save it like: For example. There is one image name 1.jpg, create the directory name 1 and inside directory there should faces stored which were present in the image 1.jpg.
  6 Comments
Image Analyst
Image Analyst on 30 Nov 2017
Remants of original discussion(before they also get deleted):
myDir = 'C:\myImages\';
this is the name of directory which contains many images. i want to detect the faces from images and want to crop the face from image and save it like: For example. There is one image name 1.jpg, create the directory name 1 and inside directory there should faces stored which were present in the image 1.jpg.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 18 Nov 2017
"i have done till face detection and cropping, but i am facing difficulty to save the cropped face "
OK, good that you've already done that, because that's the hardest part.
To save the cropped image, simply call imwrite:
baseFileName = sprintf('Face#%d.png', currentFaceIndex);
fullFileName = fullfile(outputFolder, baseFileName);
imwrite(croppedImage, fullFileName);
  2 Comments
saeeda saher
saeeda saher on 20 Nov 2017
Here is my Code .. it is for a single image but i want to apply this process on multiple images which are in directory.
and want to create a separate folder with same name as image, and save the cropped face in that directory, ex, pic name is 1.jpg, folder should be created of same name and cropped face should be saved in this folder, this process should be for all images which are in directory... kindly help me for this..
I=imread('E:\a.jpg');
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');
end
for i = 1:size(BB,1)
J= imcrop(I,BB(i,:));
% figure(3),subplot(5,5,i);imshow(J);
fname = sprintf('b_cropped_%d.jpg', i);
fpath = fullfile('E:\face', fname);
imwrite(J, fpath)
% imwrite(J,'E:\g_cropped.jpg')
end

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!