detect the number of faces on image and prompt error message if there is more than 1 face

3 visualizzazioni (ultimi 30 giorni)
Hi all,
i am doing a face detection and recognition system . I am currently using matlab R2013a with computer vision tootkit. my concern now is that i would like to allow my user to upload a image from their computer directory but in order to do so, the image must only contain 1 front face. To prevent user from uploading more than 1 face, i would like to prompt them an error message. but i am not sure how to go about it.
appreciate anyone of your help is solving the question.
[filename, pathname] = uigetfile({'*.jpg;*.png;*.gif;*.bmp', 'All Image Files (*.jpg, *.png, *.gif, *.bmp)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick an image file');
if filename ~= 0
FileName = fullfile(pathname,filename);
end
axes (handles.axes1);
F = imread (FileName);
imshow(F, 'Parent', handles.axes1);
faceDetector=vision.CascadeObjectDetector;
faceDetector.MinSize=[20 20];
faceDetector.MergeThreshold = 20;
bbox = step(faceDetector,F);
axes (handles.axes1);
imshow(F);
if numel(bbox) == 0
errordlg('No face is detected in image. Please upload another one.');
end
hold on;
for i = 1:size(bbox,1)
rectangle('Position',bbox(i,:),'LineWidth',3,'LineStyle','-','EdgeColor','r');
end
hold off;

Risposte (1)

Dima Lisin
Dima Lisin il 19 Mar 2015
bbox is an M-by-4 matrix, where is row represents a bounding box as [x, y, width, height]. So if size(bbox, 1) is 0, then no faces were detected. If size(bbox, 1) is 1, then one face was detected. If it is greater than 1, then multiple faces were detected.
  2 Commenti
Eliza Tham
Eliza Tham il 25 Mar 2015
Hi Dima, when i enter the code below, they happen to have some errors,
When i insert and image of more than 1 person, instead of giving me the error message 'Please upload another one' it prompts a message of 'Image unsuitable for enrolment. Please upload another one.'
When I enter the image without any face, it prompts me with ''Image unsuitable enrolment. Please upload another one.' which appears to be right.
Is there anything wrong with the codes, i type?
if size(bbox, 1) == 0
errordlg('Image unsuitable enrolment. Please upload another one.');
elseif size(bbox, 1)>1
errordlg('Please upload another one.');
else
msgbox('One Face detected, Image suitable to upload');
Dima Lisin
Dima Lisin il 25 Mar 2015
Look at bbox in the debugger. Draw the bounding boxes on the image. There is always the possibility that vision.CascadeObjectDetector simply did not detect all the faces.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by