Pixeling only detected face
Afficher commentaires plus anciens
% Read image
A = imread('lena512c.bmp');
%Get FaceDetector object
FaceDetector = vision.CascadeObjectDetector();
%Use FaceDetector
BBOX = step(FaceDetector, A);
%Annotation of faces
B = insertObjectAnnotation(A,'rectangle', BBOX, 'Face');
imshow(B),title('Detected Faces');
%Display number of faces
n = size (BBOX,1);
str_n = num2str(n);
str = strcat ('Number of detected faces are = ',str_n);
disp(str);
How can i pixelate just face which was detected,not whole image please?
Detector Works fine.
Réponse acceptée
Plus de réponses (1)
Ameer Hamza
le 10 Avr 2020
Modifié(e) : Ameer Hamza
le 10 Avr 2020
try this
% Read image
A = imread('lena_std.tif');
%Get FaceDetector object
FaceDetector = vision.CascadeObjectDetector();
%Use FaceDetector
BBOX = step(FaceDetector, A);
%Annotation of faces
B = insertObjectAnnotation(A,'rectangle', BBOX, 'Face');
imshow(B),title('Detected Faces');
%Display number of faces
n = size (BBOX,1);
str_n = num2str(n);
str = strcat ('Number of detected faces are = ',str_n);
disp(str);
x = BBOX(1);
y = BBOX(2);
w = BBOX(3);
h = BBOX(4);
face = A(y:y+h, x:x+w, :);
sz = size(face, [1 2]);
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face;
imshow(A)

8 commentaires
Martin Schlachta
le 10 Avr 2020
Ameer Hamza
le 10 Avr 2020
I think this is the issue with the face detection algorithm, not the pixelating. The face detection did not correctly identify the bounding box. Can you see if the bounding box covers the whole face? If bounding box is correct, can you share the original image so that i can test?
Ameer Hamza
le 10 Avr 2020
I found a mistake in my code, which will misplace the pixelation region. Please try the updated code. Specifically, I changed these two lines
face = A(y:y+h, x:x+w, :); %<--- this
sz = size(face, [1 2]);
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face; %<--- this
Martin Schlachta
le 10 Avr 2020
erik macejko
le 8 Mai 2021
Can I use this code for more than one face? If no whats the solution for recognise and censure more faces in one picture?
Image Analyst
le 8 Mai 2021
Yes, go ahead and try it.
erik macejko
le 12 Mai 2021
Thanks, and Can I ask one more thing? What is this part of code doing?
face = A(y:y+h, x:x+w, :); %% this
sz = size(face, [1 2]); %% this
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face; %% and this
Thanks for your answers
Image Analyst
le 13 Mai 2021
face = A(y:y+h, x:x+w, :); %% this crops a certain lateral ROI out of a color image.
sz = size(face, [1 2]); %% this returns the number of rows in the cropped face array as sz(1) and the number of columns as sz(2)
% Shrinks by factor of 20, then expand back to original size with replication
% to make it have a blocky appearance.
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face; %% and this puts the block image back into the original image at the original location.
Catégories
En savoir plus sur Computer Vision with Simulink dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


