detect the number of faces on image and prompt error message if there is more than 1 face
Mostrar comentarios más antiguos
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;
Respuestas (1)
Dima Lisin
el 19 de Mzo. de 2015
0 votos
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 comentarios
Eliza Tham
el 25 de Mzo. de 2015
Dima Lisin
el 25 de Mzo. de 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.
Categorías
Más información sobre ROI-Based Processing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!