Multiple face detection and cropping from multiple images
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
saeeda saher
le 10 Mai 2019
Modifié(e) : progga ilma
le 28 Déc 2019
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
0 commentaires
Réponse acceptée
progga ilma
le 28 Déc 2019
Modifié(e) : progga ilma
le 28 Déc 2019
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Point Cloud Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!