face and eye detection crop

4 visualizzazioni (ultimi 30 giorni)
Nur Izzati Nadiah
Nur Izzati Nadiah il 27 Giu 2012
Risposto: Tohru Kikawada il 13 Gen 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 Commento
Shadman Sakib Khan
Shadman Sakib Khan il 11 Dic 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.

Accedi per commentare.

Risposte (1)

Tohru Kikawada
Tohru Kikawada il 13 Gen 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!

Translated by