How to detect faces without using vision.Cas​cadeObject​Detector

I am new in matlab I am trying to detect faces without using built in functions but I not able to do this any help.

回答(1 个)

yes,sir,may be use ycbcr color segment to identify face as simple method
if possible,can you upload your image to analysis?

4 个评论

yes,sir,use simple ycbcr process,such as
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/943314/image.png');
J = rgb2ycbcr(I);
y = J(:,:,1);
[rows, cols] = size(y);
m = [120 130]';
sig = [70 40
40 200];
cbcr = zeros(2,1);
mask=zeros(rows,cols);
for i = 1:rows
for j =1:cols
cbcr(1) = J(i,j,3);
cbcr(2) = J(i,j,2);
P(i,j) = exp(-0.5*((cbcr-m)')*(inv(sig))*(cbcr-m));
end
end
mask = P < 1e-2;
bw = imopen(mask, strel('disk', 15));
bw = imclose(bw, strel('disk', 3));
bw = imfill(bw, 'holes');
bw = bwareaopen(imopen(bw, strel('disk', 25)), 2e4);
stats = regionprops(bw);
figure; imshow(I, []);
for i = 1 : length(stats)
hold on; rectangle('position', stats(i).BoundingBox, 'EdgeColor', 'g', 'LineWidth', 2)
end
Thank you for helping but this only work for this image, if I change the image it does not work properly.
yes,sir,if use different image,may be check
such as
im = imresize(I, 0.3, 'bilinear');
detector = mtcnn.Detector("MinSize", 15, "MaxSize", 308, "PyramidScale", 5);
[bboxes, scores, landmarks] = detector.detect(im);
displayIm = insertObjectAnnotation(im, "rectangle", bboxes, scores, "LineWidth", 2);
imshow(displayIm)
hold on
for iFace = 1:numel(scores)
scatter(landmarks(iFace, :, 1), landmarks(iFace, :, 2), 'filled');
end

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by