How to verify if the face has been detected ?

조회 수: 2 (최근 30일)
ABDELKARIM MELIKI
ABDELKARIM MELIKI 2019년 4월 18일
댓글: ABDELKARIM MELIKI 2019년 6월 26일
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
ABDELKARIM MELIKI
ABDELKARIM MELIKI 2019년 4월 18일
Also Iam a beginner so take it easy on me ?

댓글을 달려면 로그인하십시오.

채택된 답변

Filipe Fernandes
Filipe Fernandes 2019년 6월 24일
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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by