How to verify if the face has been detected ?
1 回表示 (過去 30 日間)
古いコメントを表示
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.
採用された回答
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!