Filter löschen
Filter löschen

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

8 Ansichten (letzte 30 Tage)
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 Kommentar
Dibya
Dibya am 22 Apr. 2013
Sorry but I could do it myself.
For example;
leye = imcrop(img, bbox(:, 5: 8));
figure;imshow(leye);
imwrite(leye,'leye.jpg');

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Adnan Rasool
Adnan Rasool am 9 Aug. 2016
Bearbeitet: Image Analyst am 22 Sep. 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 Kommentare
Sidra  Ashraf
Sidra Ashraf am 8 Jan. 2020
may this code helpful formore than 1 images???
means ihave todetect face for almost thousands images. is thiswork in loop??

Melden Sie sich an, um zu kommentieren.


Muluken  Birara
Muluken Birara am 12 Mai 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 am 22 Apr. 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 Kommentare
Dibya
Dibya am 22 Apr. 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 am 22 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by