フィルターのクリア

How to verify if the face has been detected ?

3 ビュー (過去 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
  1 件のコメント
ABDELKARIM MELIKI
ABDELKARIM MELIKI 2019 年 6 月 26 日
thank you Filipe, I did the same code ...

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by