Multiple face detection and cropping from multiple images

3 ビュー (過去 30 日間)
saeeda saher
saeeda saher 2019 年 5 月 10 日
編集済み: progga ilma 2019 年 12 月 28 日
I want to read multiple images from directory where each image contains multiple faces, I want to detect faces from each image and want to crop the detected faces and want to save these faces into another directory.
I tried the following code, It performs the face dection and cropping process on only one image. I want to perform face detection and cropping process on all of the images present in the image directory.
location = 'E:\fer1\frames\*.jpg'; % folder in which your images exists
ds = imageDatastore(location) % Creates a datastore for all images in your folder
% Loop through the datastore, read and display each image in its own window.
while hasdata(ds)
img = read(ds) ; % read image from datastore
figure, imshow(img); % creates a new window for each image
end
%figure(1);
%imshow(img);
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7 ;
BB = step(FaceDetect, img);
figure(2);
imshow(img);
for i = 1 : size(BB,1)
rectangle('Position', BB(i,:), 'LineWidth', 3, 'LineStyle', '-', 'EdgeColor', 'r');
end
for i = 1 : size(BB, 1)
J = imcrop(img, BB(i, :));
figure(3);
subplot(6, 6, i);
imshow(J);
end

採用された回答

progga ilma
progga ilma 2019 年 12 月 28 日
編集済み: progga ilma 2019 年 12 月 28 日
imds = imageDatastore ( 'face' , ...
'IncludeSubfolders' , true, ...
'LabelSource' , 'foldernames' );
idx = randperm (numel (imds.Files), 4);
j = 1;
figure
for t = 1: 4
img = readimage (imds, idx (t));
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7;
BB = step (FaceDetect, img);
figure (2);
imshow (img);
for i = 1: size (BB, 1)
rectangle ( 'Position' , BB (i, :), 'LineWidth' , 3, 'LineStyle' , '-' , 'EdgeColor' , 'r' );
end
for i = 1: size (BB, 1)
J = imcrop (img, BB (i, :));
figure (3);
subplot (6, 6, i);
imshow (J);
j = j + 1;
imwrite (J, [j, '.jpg' ])
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePoint Cloud Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by