face and eye detection crop

3 views (last 30 days)
Nur Izzati Nadiah
Nur Izzati Nadiah on 27 Jun 2012
Answered: Tohru Kikawada on 13 Jan 2017
I detect the face using function available in computer vision system toolbox bbox = step(faceDetector, I);
I insert the box for detected face imageOut = step(boxInserter, I, uint8(bbox));
As a result, Some image has two or three boxes at the target subject. For example, I use this to detect the face, and some of the image have two box that detect the face in one image.
Crop Icrop = imcrop(I,bbox);
The problem is when I want to crop the detected face, it is error due to multiple bbox appear in the image.
How to solve this problem?
Thanks
  1 Comment
Shadman Sakib Khan
Shadman Sakib Khan on 11 Dec 2016
As far I know imcrop function can only crop using the parameter (x,y ,width, height). But in your bbox there are four corner position of the polygon. That's why the error occurs. But if you already solve the problem, can you please give me the solution of cropping an image using four corner point.

Sign in to comment.

Answers (1)

Tohru Kikawada
Tohru Kikawada on 13 Jan 2017
You can use cellfun for processing multiple ROIs as follows:
%%Create a detector object.
faceDetector = vision.CascadeObjectDetector;
%%Read input image.
I = imread('visionteam.jpg');
%%Detect faces.
bboxes = step(faceDetector, I);
%%Convert bboxes to cell arrays
bboxesCell = mat2cell(bboxes,ones(size(bboxes,1),1),size(bboxes,2));
%%Crop detected faces.
facesCropped = cellfun(@(x)imcrop(I,x),bboxesCell,'UniformOutput',false)
%%Display a cropped image
imshow(facesCropped{1});

Community Treasure Hunt

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

Start Hunting!