Borrar filtros
Borrar filtros

How to crop a detected face and face parts and save them as separate images?

8 visualizaciones (últimos 30 días)
I am using the detectfacepart code of the following link ( http://www.mathworks.in/matlabcentral/fileexchange/36855-face-parts-detection) for detecting the face and face parts. How can I crop the detected face and face parts and save them as separate images?
  1 comentario
Dibya
Dibya el 22 de Abr. de 2013
Sorry but I could do it myself.
For example;
leye = imcrop(img, bbox(:, 5: 8));
figure;imshow(leye);
imwrite(leye,'leye.jpg');

Iniciar sesión para comentar.

Respuestas (3)

Adnan Rasool
Adnan Rasool el 9 de Ag. de 2016
Editada: Image Analyst el 22 de Sept. de 2017
Asslam o Alikum
Here is the code for
  1. Select image from a Location
  2. Detect faces in the selected image
  3. Find the Location of Detected Faces
  4. Crop all detected faces on one Figure
%Code start
clc;
[filename, folder] = uigetfile ({'*.jpg';'*.bmp';'*.png'}, 'File Selector');
fullFileName = fullfile(folder, filename);
img = imread(fullFileName);
figure(1);
imshow(img);
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7 ;
BB = step(FaceDetect, img);
figure(2);
imshow(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);
end
%Code End
If this Helped: Remember me in your Prayers
Thanks
  6 comentarios
Sidra  Ashraf
Sidra Ashraf el 8 de En. de 2020
may this code helpful formore than 1 images???
means ihave todetect face for almost thousands images. is thiswork in loop??

Iniciar sesión para comentar.


Muluken  Birara
Muluken Birara el 12 de Mayo de 2017
i want to proposed to work lip detection from image sequence , but know i cant preprocessed several image file
  • how to detect multi face image using loop
  • how to crop then and stror new dir for farther processing

Image Analyst
Image Analyst el 22 de Abr. de 2013
Make sure you're passing [leftColumn, topRow, numberOfColumns, numberOfRows] as the second argument to imcrop. I'm not sure what you're passing. If you pass the right thing, it will work.
  2 comentarios
Dibya
Dibya el 22 de Abr. de 2013
Thanks for your response. Yes,the bbox(:,5:8) contains the bounding box i.e (xmin,ymin,width,height)for left eye in that example.
Image Analyst
Image Analyst el 22 de Abr. de 2013
I don't think it does, because you have : which means "all rows" so there is likely more than 4 numbers there. Try this before you call imcrop():
croppingRectangle = bbox(:, 5:8) % No semicolon
whos croppingRectangle
and tell us what it says.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by