首页 > 安全资讯 >

face recognition matlab code 人脸识别

13-12-08

实现了一下linear regression classification for face recognition %contact quxiaochao@gmail com function FR_LR close all; clear all; clc; %%%%%% load( & 039;N mat & 039;) load( & 039;H mat & 039;) load

实现了一下linear regression classification for face recognition

%contact quxiaochao@gmail.com


function FR_LR
close all;
clear all;
clc;






%%%%%%
load('N.mat')
load('H.mat')
load('S.mat')
load('A.mat')


load('N_label.mat')
load('H_label.mat')
load('S_label.mat')
load('A_label.mat')






Tr_DAT = double([S ]);
trls = [S_label ]';
Tt_DAT = double([N H A ]);
ttls = [N_label H_label A_label]';
clear NewTest_DAT NewTrain_DAT testlabels trainlabels
%%%%%%
%
% load('ORL_DAT_1_train.mat')
% Tr_DAT = double(ORL_DAT{1});
% Tt_DAT = double(ORL_DAT{2});
% trls = ORL_DAT{3};
% ttls = ORL_DAT{4};
% trls = trls'
% ttls = ttls'
%


% load(['AR_DAT']);
% Tr_DAT = double(NewTrain_DAT(:,:));
% trls = trainlabels(:);
% Tt_DAT = double(NewTest_DAT(:,:));
% ttls = testlabels(:);
% clear NewTest_DAT NewTrain_DAT testlabels trainlabels


for i = 1:size(Tr_DAT,2)
temp = Tr_DAT(:,i);
Tr_DAT(:,i) = Tr_DAT(:,i)./(norm(temp));
end


for i = 1:size(Tt_DAT,2)
temp = Tt_DAT(:,i);
Tt_DAT(:,i) = Tt_DAT(:,i)./(norm(temp));
end


class_set = unique(trls)
class_model_projection_matrix = cal_class_model(Tr_DAT,trls);
for i = 1:size(Tt_DAT,2)
temp = Tt_DAT(:,i);
label(i) = classify_face(class_model_projection_matrix,temp)
end


difference = find(label' ~= ttls);
1 - size(difference,1)/(size(Tt_DAT,2))




function class_model_projection_matrix = cal_class_model(Tr_DAT,trls)
class_set = unique(trls);
for i = 1:1:size(class_set,1)
index = find(trls == class_set(i));
class_model_data = Tr_DAT(:,index);
class_model_projection_matrix{i} = class_model_data*inv(class_model_data'*class_model_data)*class_model_data';

end




function label = classify_face(p_matrix,test_face)
for i = 1:1:size(p_matrix,2)
test_face_predicted = p_matrix{i}*test_face;
error = test_face_predicted - test_face;
class_error(i) = norm(error);
end
[class_error index] = sort(class_error);
label = index(1);

相关文章
最新文章
热点推荐