detect the number of faces on image and prompt error message if there is more than 1 face
Ältere Kommentare anzeigen
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;
Antworten (1)
Dima Lisin
am 19 Mär. 2015
0 Stimmen
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 Kommentare
Eliza Tham
am 25 Mär. 2015
Dima Lisin
am 25 Mär. 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.
Kategorien
Mehr zu ROI-Based Processing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!