detect the number of faces on image and prompt error message if there is more than 1 face
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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;
0 Commenti
Risposte (1)
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
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.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!