i have code for extracting multiple faces from an image and cropping these extracted faces from image, now i want to save these cropped faces in a folder , how can i do that??

clc;
I=imread('E:/g.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);
end

 Réponse acceptée

Hello Saeeda,
You can use imwrite to save images to a file.
imwrite(J, 'E:\g_cropped.jpg')
-Cam

5 commentaires

*
I am applying this but it saves only one cropped image, not the all cropped faces.. how to save all of them??*
clc;
I=imread('E:\g.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);
imwrite(J, 'E:\g_cropped.jpg')
end
Since you are calling imwrite in a for loop, it is actually saving each of the different J values. However, you have it saving to the same filename each time. I assumed that you would want your own naming convention, and could add that. Something like:
fname = sprintf('g_cropped_%d.jpg', i);
fpath = fullfile('E:', fname);
imwrite(J, fpath)
You can customize the name and path or anything you feel like as you like. This is just for illustration purposes.
-Cam
i want to apply facial expression recognition on the cropped images. kindly, guide me.
That is not an easy problem that someone can simply "guide you" through. There are actually challenges where people can win money for solving that kind of problem.
There are some suggested products and workflows on the MathWorks site, but it will require significant amount of data (classified images) to start with as a baseline. Depending on how you define your problem, you may be able to find papers/work done by others on this problem to advance you further, or you may have to do the majority of it yourself. But either way, I'd start with some scholarly article review.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by