⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 detection.m

📁 source compute projection lda
💻 M
字号:
function detection
clear all;
prompt = {'Enter your address database :','Enter your number face database:','Enter your address face for detection:','address of load train_wt','address of load train_mean','address of load P'};
def = {'G:\projects\face detection\yalefaces\1 (','130','G:\projects\face detection\yalefaces\1 (5).jpg','G:\projects\face detection\yalefaces\eigenvector\train_wt','G:\projects\face detection\yalefaces\eigenvector\train_mean','G:\projects\face detection\yalefaces\eigenvector\P'};
dlg_title = 'Input for peaks function';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines,def);
pp=cell2mat(answer(1));
count_of_face=cell2mat(answer(2));
count_of_face=str2num(count_of_face);
path_pattern=cell2mat(answer(3));
train_wt=cell2mat(answer(4));
train_mean=cell2mat(answer(5));
P=cell2mat(answer(6));

f=').jpg';
for i=1:count_of_face%130
    tmp=int2str(i);
    p=[pp,tmp,f];
    database(:,:,:,i)=imread(p);
    [nx mx rgb ss]=size(database);
    if (rgb>2)
       database_gray(:,:,i)=rgb2gray(database(:,:,:,i));
    else 
        database_gray(:,:,i)=database(:,:,:,i);
    end
   % l(:,:,:,i)
end 

[Nx Ny M] = size(database_gray);

load (P);
load (train_mean);
load (train_wt);
[count count_of_face]=size(train_wt);
%[s1 s2]=size(train_mean);
im=imread(path_pattern);

%M=count_of_face;
%Nx=round(s1/Ny);
threshFace=count_of_face;%130
numberofclass_org=count;
threshClass=numberofclass_org;%10
im=imresize(im,[Nx Ny]);
m1=1;
tic
[nx ny m1]=size(im);
if m1>2 
    recog_I=rgb2gray(im);%database_gray(:,:,67);%database(:,:,78);%feaD(:,:,150);%database_gray(:,:,50);%feaD(:,:,150);%un(:,:,20);
else 
    recog_I=im;
end
    [Nx Ny M2] = size(recog_I);

% Init some values
Mp = length(P(1,:));
X2 = double(reshape(recog_I,[Nx*Ny M2]))./256; % 1 column per face
A2 = X2 - repmat(train_mean,[1 M2]);
% Project each face in recog set onto eigenfaces, storing weight
recog_wt = P'*A2;
% Reconstruct projected faces
R = P*recog_wt + repmat(train_mean,[1 M2]);

% Plot reconstructed images
close all;
plots_intermediateOn=1;
plots_savePlotsOn=1;
if plots_intermediateOn
	I = reshape(R,[Nx Ny 1 M2]);
	for i = 1:M2 % scale for plot
        mx = max(R(:,i));
        mi = min(R(:,i));
        I(:,:,1,i) = (I(:,:,1,i)-mi)./(mx-mi);
	end 
	figure,montage(I),title('reconst recog images')
    if plots_savePlotsOn, saveas(gcf,'reconst_recog_images','png'), end
end

% Find euclidian distance from each recog face to each known face
recog_euDis = zeros(M,M2);
for i = 1:M2 % each recog face
    for j = 1:M % each known face class
        recog_euDis(j,i) = sqrt(sum((recog_wt(:,i) - train_wt(:,j)).^2));
    end
end

[minDis ndx] = min(recog_euDis);
	
fprintf('Results of face recognition:\n')
for i = 1:M2 % each recog face
    if round(minDis(i)) > 8
        imshow(imresize(recog_I,[200 200]));title('NoN face','FontSize',15,'Color','r')
        errordlg('NoN face');
    elseif minDis(i) > threshClass
         errordlg('UnknownFace');
       
    else if round(minDis)<1
        str1='Success face index =';
        str3='  Time Process=';
        se='sec'
        str2=num2str(ndx);
        time=toc;
        time=num2str(time);
        message=[str1,str2,str3,time,se];
        close all;
       %im1=imresize(recog_I,6);
      % im2=imresize(database_gray(:,:,ndx),6);
       subplot(1,2,1), imshow(imresize(recog_I,[200 200]));title('Pattern face','FontSize',15,'Color','r')
       subplot(1,2,2), imshow(imresize(database_gray(:,:,ndx),[200 200]));title('Pattern Recognition of facce','FontSize',15,'Color','g')
      
     % subplot(1,2,1), imshow(im1);title('Pattern face','FontSize',15,'Color','r')
     % subplot(1,2,2), imshow(im2);title('Pattern Recognition of facce','FontSize',15,'Color','g');
      warndlg(message,'success');
        else  if round(minDis)>2 && round(minDis)<7
           imshow(imresize(recog_I,[200 200]));title('Other face','FontSize',15,'Color','r')
           errordlg('other face');
            end
        end
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -