필터 지우기
필터 지우기

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??

댓글을 달려면 로그인하십시오.


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