フィルターのクリア

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

8 ビュー (過去 30 日間)
Dibya
Dibya 2013 年 4 月 22 日
コメント済み: Image Analyst 2020 年 1 月 9 日
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 件のコメント
Dibya
Dibya 2013 年 4 月 22 日
Sorry but I could do it myself.
For example;
leye = imcrop(img, bbox(:, 5: 8));
figure;imshow(leye);
imwrite(leye,'leye.jpg');

サインインしてコメントする。

回答 (3 件)

Adnan Rasool
Adnan Rasool 2016 年 8 月 9 日
編集済み: Image Analyst 2017 年 9 月 22 日
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 件のコメント
Sidra  Ashraf
Sidra Ashraf 2020 年 1 月 8 日
may this code helpful formore than 1 images???
means ihave todetect face for almost thousands images. is thiswork in loop??
Image Analyst
Image Analyst 2020 年 1 月 9 日
Sidra, of course. See the FAQ

サインインしてコメントする。


Muluken  Birara
Muluken Birara 2017 年 5 月 12 日
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 2013 年 4 月 22 日
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 件のコメント
Dibya
Dibya 2013 年 4 月 22 日
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 2013 年 4 月 22 日
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by