Readme

人脸识别GUI设计

这是我在理解PCA算法后,设计MATLAB GUI实现人脸识别。

使用方法:

  1. 运行face.m主脚本
  2. 点击训练机器选择train文件夹
  3. 点击choose photo选择test文件夹下的一张图片
  4. 最后点击recognize即可进行识别
  5. 点击Accuracy可计算整个test文件夹下所有图识别准确率

效果如下:

在这里插入图片描述](https://img-blog.csdnimg.cn/2019010116254575.png?x-oss-在这里插入图片描述
在这里插入图片描述`附录:MATLAB 核心代码
% pushbutton1(选择图片)按钮按下时执行
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% 读取要识别的图像
global im;
[filename, pathname] = uigetfile({’*.bmp’},‘choose photo’);
str = [pathname, filename];
im = imread(str);
axes( handles.axes1);
imshow(im);

% pushbutton2(人脸识别)按钮按下时执行
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

global im
global reference
global W
global imgmean
global col_of_data
global pathname
global img_path_list

% 预处理新数据
im = double(im(😃);
objectone = W’*(im - imgmean);
distance = 100000000;

% 最小距离法,寻找和待识别图片最为接近的训练图片
for k = 1:col_of_data
temp = norm(objectone - reference(:,k));
if(distance>temp)
aimone = k;
distance = temp;
aimpath = strcat(pathname, ‘/’, img_path_list(aimone).name);
axes( handles.axes2 )
imshow(aimpath)
end
end

% 显示测试结果
% aimpath = strcat(pathname, ‘/’, img_path_list(aimone).name);
% axes( handles.axes2 )
% imshow(aimpath)

%pushbutton3(训练机器)按钮按下时执行
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

global reference
global W
global imgmean
global col_of_data
global pathname
global img_path_list

% 批量读取指定文件夹下的图片128*128
pathname = uigetdir;
img_path_list = dir(strcat(pathname,’*.bmp’));
img_num = length(img_path_list);
imagedata = [];
if img_num >0
for j = 1:img_num
img_name = img_path_list(j).name;
temp = imread(strcat(pathname, ‘/’, img_name));
temp = double(temp(😃);
imagedata = [imagedata, temp];
end
end
col_of_data = size(imagedata,2);

% 中心化 & 计算协方差矩阵
imgmean = mean(imagedata,2);
for i = 1:col_of_data
imagedata(:,i) = imagedata(:,i) - imgmean;
end
covMat = imagedata’*imagedata;
[COEFF, latent, explained] = pcacov(covMat);

% 选择构成95%能量的特征值
i = 1;
proportion = 0;
while(proportion < 95)
proportion = proportion + explained(i);
i = i+1;
end
p = i - 1;

% 特征脸
W = imagedataCOEFF; % NM阶
W = W(:,1:p); % N*p阶

% 训练样本在新座标基下的表达矩阵 p*M
reference = W’*imagedata;在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值