📄 svmfacedetection.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function svmFaceDetection()
% z.li, 12-16-2003.
% show face with gnd truth
% function dependency:
% - faceProb()
% input:
% img -
% sWin - search windows, nx2. [w h]
% styl - plot styl, no plot if 'no'
% output:
% face - facial area sub image
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function [pos]=svmFaceDetection(img, sWin, styl)
function [pos]=svmFaceDetection(img, sWin, styl)
dbg = 'n';
if dbg == 'y'
sWin= [24 32; 30 45];
img = imread('k:/work/Face/matlab/seinfeld3.jpg', 'jpg');
imshow(img, [0 255]);
end
% const
W = 12; H=16;
T1 = load('pcaFaceW12H16.dat');
T2 = load('pcaUpperFaceW12H16.dat');
T3 = load('pcaLowerFaceW12H16.dat');
mT1Face = [-1272.06 -15.11 -39.26 14.88 -5.77 -0.10 -27.21 -14.04 46.88 5.41 34.97 -19.03 ]';
mT2Face = [-914.5640 45.0144 -20.0134 52.3669 11.8582 4.5829 -1.4717 -15.0933]';
mT3Face = [-880.6135 -36.5670 -6.7102 40.6621 -26.8938 19.7570 -25.5042 -0.2695]';
% var
[h w] = size(img);
[nScale d2] = size(sWin);
pos=[]; cnt = 0;
for s=1:nScale
% search window size
sW=sWin(s,1); sH=sWin(s,2);
fprintf('\n scale=%d, sW=%d sH=%d', s, sW, sH);
% search
xcnt=0; ycnt=0;
for y=1:h-sH
for x=1:w-sW
if ycnt == 2 & xcnt == 2
ycnt=0; xcnt=0;
face = img(y:y+sH-1,x:x+sW-1);
[icon, vec]=scaleImage(face, W, H);
prob = faceProb(T1, T2, T3, mT1Face, mT2Face, mT3Face, vec, '.r');
if prob == 1
cnt = cnt+1;
pos(cnt,1:4) = [x y sW sH];
fprintf('+');
end
fprintf('.');
else
ycnt=ycnt+1; xcnt=xcnt+1;
end
end
fprintf('\n %d> ', y);
end
end
if styl ~= 'no'
imshow(img, [0 255]); hold on;
for j=1:cnt
%[x y dw dh] = pos(j,1:4);
plotBox(pos(j,1), pos(j,2), pos(j,3), pos(j,4), styl);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -