Effacer les filtres
Effacer les filtres

How to verify if the face has been detected ?

1 vue (au cours des 30 derniers jours)
ABDELKARIM MELIKI
ABDELKARIM MELIKI le 18 Avr 2019
My code is:
while hasFrame(videoFileReader)
videoFrame = readFrame(videoFileReader);
bbox = faceDetector(videoFrame); %detect the face
videoFrame = insertShape(videoFrame, 'Rectangle', bbox); % place a box around the face
%% i want to add an IF statment to verify first if bbox is true !
%crop the rounded face and save it
FacCrop=imcrop(videoFrame,bbox);
fname = sprintf('FaceCropped_%d.jpg',i);
fpath = fullfile('E:', fname);
imwrite(FacCrop, fpath);
i=i+1;
end
  • but since there's some frames where the face can't be detected, that means no bbox, so it returns an error in the imcrop function and won't finnish the rest of the video !
Error using images.internal.imageDisplayParsePVPairs (line 125)
Invalid input arguments.
Error in images.internal.imageDisplayParseInputs (line 69)
[common_args,specific_args] = images.internal.imageDisplayParsePVPairs(varargin{:});
Error in imshow (line 245)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in imcrop>parseInputs (line 252)
imshow(a,cm);
Error in imcrop (line 93)
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:});
Error in FaceTracking (line 19)
FacCrop=imcrop(videoFrame,bbox);
So what i want, is first to verify if the face has been detected or not in bbox, to call the crop function, else, skipp the crop step.
I hope you get my problem, and I hope I find a solution from you guys.
Thanks in advance.
  1 commentaire
ABDELKARIM MELIKI
ABDELKARIM MELIKI le 18 Avr 2019
Also Iam a beginner so take it easy on me ?

Connectez-vous pour commenter.

Réponse acceptée

Filipe Fernandes
Filipe Fernandes le 24 Juin 2019
Hello, you could try use
while hasFrame(videoFileReader) videoFrame = readFrame(videoFileReader);
bbox = faceDetector(videoFrame); %detect the face
if ~isempty(bbox)
videoFrame = insertShape(videoFrame, 'Rectangle', bbox); % place a box around the face
%crop the rounded face and save it
FacCrop=imcrop(videoFrame,bbox);
fname = sprintf('FaceCropped_%d.jpg',i);
fpath = fullfile('E:', fname);
imwrite(FacCrop, fpath);
end
i=i+1;
end
  1 commentaire
ABDELKARIM MELIKI
ABDELKARIM MELIKI le 26 Juin 2019
thank you Filipe, I did the same code ...

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by