How can I deal or track only one face while I have detected all the faces in front of camera?

3 visualizzazioni (ultimi 30 giorni)
I have face recognition code which recognizes the face and show its name when I will generate the database for that, it is working well when only one face is in front of camera but I am using "FaceDetect = vision.CascadeObjectDetector;" for face detection which will detect all the faces in front of camera and I am getting bounding box around all the faces. Is there any way to track face of my choice among the detected all faces? Or can I code each bounding box face separately? Please give me some guideline. Thanks

Risposta accettata

Aurele Turnes
Aurele Turnes il 5 Ago 2014
Once you have created your vision.CascadeObjectDetector object, you can apply it to your image I to detect the faces on the image as follows:
bboxes = step(faceDetect, I);
The returned matrix bboxes is M-by-4, where M is the number of faces detected and the 4 elements describe the bounding box around each face, as explained in the following documentation page:
To access the ith face, you can simply extract the corresponding pixels from the original image:
i = 1;
indexi = bboxes(i,:);
facei = I(indexi(2):indexi(2)+indexi(4),indexi(1):indexi(1)+indexi(3),:);
figure;
imagesc(facei)
You can then pass facei to your face recognition algorithm to detect which person this face corresponds to and track who is on the picture.
  3 Commenti
talal
talal il 13 Ago 2014
Modificato: Image Analyst il 15 Ago 2014
Dear Turnes,
First of all thanks for your answer. I am following your guidelines but I am facing some problems can you please help me.
index1=bbox(1,:);
face1=temp(index1(2):index1(2)+index1(4),index1(1):index1(1)+index1(3),:);
G=rgb2gray(face1);
R=imresize(G,[100,100]);
% imagesc(face1)
name1=recognize(R); .....my face recognition function
and I am getting error
Error using rgb2gray>parse_inputs (line 81)
MAP must be a m x 3 array.
Error in rgb2gray (line 35)
X = parse_inputs(varargin{:});
Error in get_face (line 11)
img=rgb2gray(img);
Thanks in advance
Aurele Turnes
Aurele Turnes il 15 Ago 2014
It seems like you are getting an error when you use the rgb2gray function because your frame face1 is only a 2D-matrix. The function rgb2gray expects its input to be in color, and thus to be a 3D-matrix. Can you check if your face1 frame is a 3D-matrix?

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 6 Ago 2014

Community Treasure Hunt

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

Start Hunting!

Translated by