Face Detection Isolating faces

2 views (last 30 days)
Jonathan
Jonathan on 25 Oct 2013
Hi guys, I have recently tried the viola jones cascedeobjectdetector to detect faces and it works great. The only thing that I am having trouble is to crop out the faces, isolate and save them individually. have used the icrop function but still stuck thinking of a method to isolate them.. Anyone have any idea?
  1 Comment
Jonathan
Jonathan on 25 Oct 2013
At the moment I can only do one lame thing which is this. I=imread('1.jpg'); %I = rgb2gray(I); faceDetector = vision.CascadeObjectDetector(); bbox_face = step(faceDetector, I);
I_faces = insertObjectAnnotation(I, 'rectangle', bbox_face, 'Face'); figure, imshow(I_faces), title('Detected faces');
for i=1: length(bbox_face) Icrop= imcrop(I,bbox_face(i,:));
Y= Icrop; if i==1 imwrite(Y,'cropped.jpg'); elseif i==2 imwrite(Y,'cropped2.jpg' ); elseif i==3 imwrite(Y,'cropped3.jpg'); else imwrite(Y,'cropped4.jpg' );
end end
Do advice if theres a better way :D

Sign in to comment.

Answers (1)

Anandakumar Selvaraj
Anandakumar Selvaraj on 27 Nov 2013
you can try this code to crop the face
faceBBox = step(faceDetector,videoFrame);
x = faceBBox(1); y = faceBBox(2); w = faceBBox(3); h = faceBBox(4);
bboxPolygon = [x, y, x+w, y, x+w, y+1.56*h, x, y+1.56*h];
face = imcrop(videoFrame,faceBBox);

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!