face detection of multiple faces inside one image
22 ビュー (過去 30 日間)
古いコメントを表示
I tried the following code, It performs the face dection and cropping process on only one image(contain only one face) and only crope one face . I want to perform face detection and cropping process on multiple faceses inside an image .
location = 'C:\Users\TOSHIBA\Desktop\FACE'; % 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, :));
I = rgb2gray(J); % change to gray scale
resizedimage = imresize(I, [112 92]);
figure(3);
subplot(1, 1, i);
imshow(resizedimage); % show gray scale
imsave
end
0 件のコメント
回答 (2 件)
Subhadeep Koley
2019 年 10 月 31 日
You can step() the instantiated objects on the image of interest. The CascadeObjectDetector returns the bounding boxes of the detected objects, and the ShapeInserter delimits them in the image.
Use the code below to detect and crop multiple faces from an image.
% Initialize the detector
faceDetector = vision.CascadeObjectDetector;
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[0 255 0]);
% Read the image
I = imread('solvey.jpg'); % Read your image here
imshow(I);
bbox = step(faceDetector, I);
% Draw boxes around detected faces and display results
I_faces = step(shapeInserter, I, int32(bbox));
figure;imshow(I_faces), title('Detected faces');
% Cropping individual faces
for i=1:size(bbox,1)
face = imresize(imcrop(I,bbox(i,:)),[60 60]);
figure;imshow(face,[]);
end
LALITH
2024 年 8 月 2 日
% Initialize the detector
faceDetector = vision.CascadeObjectDetector;
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[0 255 0]);
% Read the image
I = imread('solvey.jpg'); % Read your image here
imshow(I);
bbox = step(faceDetector, I);
% Draw boxes around detected faces and display results
I_faces = step(shapeInserter, I, int32(bbox));
figure;imshow(I_faces), title('Detected faces');
% Cropping individual faces
for i=1:size(bbox,1)
face = imresize(imcrop(I,bbox(i,:)),[60 60]);
figure;imshow(face,[]);
end
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!