Pixeling only detected face
Mostrar comentarios más antiguos
% 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.
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 10 de Abr. de 2020
Editada: Ameer Hamza
el 10 de Abr. de 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 comentarios
Martin Schlachta
el 10 de Abr. de 2020
Ameer Hamza
el 10 de Abr. de 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
el 10 de Abr. de 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
el 10 de Abr. de 2020
erik macejko
el 8 de Mayo de 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
el 8 de Mayo de 2021
Yes, go ahead and try it.
erik macejko
el 12 de Mayo de 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
el 13 de Mayo de 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.
Categorías
Más información sobre Computer Vision with Simulink en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


