利用MATLAB实现人脸识别GUI程序设计

%% 人脸识别
clc;clear;close all;
%% 加载文件路径
addpath(genpath('F:\课程\模式识别\'));
%% --------- 训练集图像文件-------
Train_file_path = 'F:\课程\模式识别\实验四数据\TrainDatabase\ORL\';
Train_data_list = dir(strcat(Train_file_path));
%------训练集图像元胞分配内存-----%
Train_image=cell(size(Train_data_list,1),8);
Train_image_line=cell(8*size(Train_data_list,1),1);
%--------遍历得到训练集图像-------%
k=1;
for i=3:size(Train_data_list,1)img_file=Train_data_list(i).name;% 获取文件夹名称Train_img_list=dir(strcat(Train_file_path,img_file,'\*.jpg'));% 获取文件夹下图像img_num = length(Train_img_list);%获取图像总数量for j = 1:img_num %逐一读取图像Train_image_name = Train_img_list(j).name;% 图像名image = imread(strcat(Train_file_path,img_file,'\',Train_image_name));Train_image{i,j}=image; % 存入元胞数组Train_image_line{k,1}=image; % 存入元胞数组k=k+1;fprintf('%d %d %s\n',i,j,strcat(Train_file_path,img_file,'\',Train_image_name));% 显示正在处理的图像名end
end
%---------删除空余两行---------%
%---小括号删除元素,大括号置空--%
Train_image(1,:)=[];
Train_image(2,:)=[];
Train_image_line(321:336)=[];%% 图像宽92,高112,8bit
All_Train_img=zeros(8*(size(Train_data_list,1)-2),112*92);
% 建立所有训练集图像矩阵
% for i=1:320
%     Temp=Train_image_line{i,1};
%     Temp=Temp';% 先转置
%     Temp=Temp(:);% 再行向化
%     All_Train_img(i,:)=Temp;
% end
for i=1:320Temp=Train_image_line{i,1};Temp=Temp(:);Temp=Temp';All_Train_img(i,:)=Temp;
end
% 求所有图片各像素平均值(平均脸)
image_mean=mean(All_Train_img,1);
% 求所有图片像素点位-平均值(中心化)
all_img_diff=zeros(320,92*112);
for i=1:320all_img_diff(i,:)=All_Train_img(i,:)-image_mean;
end
% 求协方差矩阵
sigma_mat=all_img_diff*all_img_diff';
% 求特征值和特征向量
[U , D]=eig(sigma_mat);%为什么这里是已经排序好的特征值
% 对特征值进行排序
D_diag=diag(D); %取对角线元素
[D_sort,index]=sort(D_diag,'descend'); %以降序排序
Sum_D = sum(D_sort);%对所有特征值求和
temp = 0;
for i = 1:size(All_Train_img,1)temp = temp + D_sort(i,1);m = i;if (temp/Sum_D >0.95)%特征值占比95%break;end
end
U1 = U(:,index);%按照特征值的索引排序特征向量
New_U = U1(:,1:m);% 选取95%对应的特征向量组成矩阵
% 特征脸
Feature_face=all_img_diff'*New_U;
% 特征脸投影
Pn=All_Train_img*Feature_face;
save('F:\课程\模式识别\Feature_face.mat','Feature_face');
save('F:\课程\模式识别\Pn.mat','Pn')
save('F:\课程\模式识别\image_mean.mat','image_mean')
function varargout = exp_4_GUI(varargin)
% EXP_4_GUI MATLAB code for exp_4_GUI.fig
%      EXP_4_GUI, by itself, creates a new EXP_4_GUI or raises the existing
%      singleton*.
%
%      H = EXP_4_GUI returns the handle to a new EXP_4_GUI or the handle to
%      the existing singleton*.
%
%      EXP_4_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EXP_4_GUI.M with the given input arguments.
%
%      EXP_4_GUI('Property','Value',...) creates a new EXP_4_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before exp_4_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to exp_4_GUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help exp_4_GUI% Last Modified by GUIDE v2.5 10-Dec-2020 18:01:46% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @exp_4_GUI_OpeningFcn, ...'gui_OutputFcn',  @exp_4_GUI_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before exp_4_GUI is made visible.
function exp_4_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to exp_4_GUI (see VARARGIN)% Choose default command line output for exp_4_GUI
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes exp_4_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = exp_4_GUI_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;% --- Executes on button press in 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)
addpath(genpath('F:\课程\模式识别\实验四数据\TestDatabase\'));
[FileName,PathName] = uigetfile('F:\课程\模式识别\实验四数据\TestDatabase\*.jpg','请选择一幅图像');
[picture_in_one,map]=imread(FileName);%imread函数实现图像导入
axes(handles.axes1);  %用axes命令设定当前操作的坐标轴
imshow(picture_in_one);
title('测试人脸');
% handles.axes1=picture_in_one;
handles.picture_in_one=picture_in_one;
guidata(hObject,handles);%使用guidata函数保存该句柄结构% --- Executes on button press in 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)
% 通过句柄得到图片
%picture=handles.axes1;% uint8的图片
picture=handles.picture_in_one;% uint8的图片
picture_line = double(picture(:));
% New_U=importdata('F:\课程\模式识别\New_U.mat');
Feature_face=importdata('F:\课程\模式识别\Feature_face.mat');
Pn=importdata('F:\课程\模式识别\Pn.mat');
P=(picture_line)' * Feature_face;
% 最小距离法,寻找和待识别图片最为接近的训练图片
dist=zeros(size(Pn,1),1);
for k = 1:size(Pn,1)temp=(P - Pn(k,:)).^2;dist(k)= sqrt(sum(temp(:)));    %欧氏距离
end
[~,id]=sort(dist,'ascend');   %筛选出距离前三小的
% --------- 训练集图像文件-------
Train_file_path = 'F:\课程\模式识别\实验四数据\TrainDatabase\ORL\';
Train_data_list = dir(strcat(Train_file_path));
%------训练集图像元胞分配内存-----%
Train_image=cell(size(Train_data_list,1),8);
Train_image_line=cell(8*size(Train_data_list,1),1);
%--------遍历得到训练集图像-------%
k=1;
for i=3:size(Train_data_list,1)img_file=Train_data_list(i).name;% 获取文件夹名称Train_img_list=dir(strcat(Train_file_path,img_file,'\*.jpg'));% 获取文件夹下图像img_num = length(Train_img_list);%获取图像总数量for j = 1:img_num %逐一读取图像Train_image_name = Train_img_list(j).name;% 图像名image = imread(strcat(Train_file_path,img_file,'\',Train_image_name));Train_image{i,j}=image; % 存入元胞数组Train_image_line{k,1}=image; % 存入元胞数组k=k+1;fprintf('%d %d %s\n',i,j,strcat(Train_file_path,img_file,'\',Train_image_name));% 显示正在处理的图像名end
end
%---------删除空余两行---------%
%---小括号删除元素,大括号置空--%
Train_image_line(321:336)=[];
X1=Train_image_line{id(1,1),:};
X2=Train_image_line{id(2,1),:};
X3=Train_image_line{id(3,1),:};
axes( handles.axes2 )
imshow(X1);
axes( handles.axes3 )
imshow(X2);
axes( handles.axes4 )
imshow(X3);% --- Executes during object creation, after setting all properties.
% 测试图片
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色
set(gca,'YColor',get(gca,'Color'));set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度
set(gca,'YTickLabel',[]);
% Hint: place code in OpeningFcn to populate axes1% 识别图片
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色
set(gca,'YColor',get(gca,'Color'));set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度
set(gca,'YTickLabel',[]);
% Hint: place code in OpeningFcn to populate axes2% 识别图片
% --- Executes during object creation, after setting all properties.
function axes3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色
set(gca,'YColor',get(gca,'Color'));set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度
set(gca,'YTickLabel',[]);
% Hint: place code in OpeningFcn to populate axes3% 识别图片
% --- Executes during object creation, after setting all properties.
function axes4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(gca,'XColor',get(gca,'Color')) ;% 这两行代码功能:将坐标轴和坐标刻度转为白色
set(gca,'YColor',get(gca,'Color'));set(gca,'XTickLabel',[]); % 这两行代码功能:去除坐标刻度
set(gca,'YTickLabel',[]);
% Hint: place code in OpeningFcn to populate axes4





利用MATLAB实现人脸识别GUI程序设计相关推荐

  1. 利用MATLAB进行人脸识别

     最近要给同学在一个自动瞄准装置的基础上做一个人脸识别模块.也是上网查阅了一些资料,经过一周的整理整合,也算是有一些收获. 首先,通过阅读网上的一些现有的程序,可以发现,人脸识别大致可以分为两种方 ...

  2. 基于MATLAB的人脸识别系统[创新元素,界面GUI]

    第一章 绪论 本章提出了本文的研究背景及应用前景.首先阐述了人脸图像识别意义:然后介绍了人脸图像识别研究中存在的问题:接着介绍了自动人脸识别系统的一般框架构成:最后简要地介绍了本文的主要工作和章节结构 ...

  3. 基于MATLAB的人脸识别系统GUI

    基于MATLAB的人脸识别系统GUI,可以识别出不同表情的人脸 演示视频:[基于matlab人脸识别系统-哔哩哔哩] https://b23.tv/Pj8j0Uu 运行截图: 源码获取+卫星:DX52 ...

  4. 基于Matlab的人脸识别登录系统

    基于Matlab的人脸识别登录系统 摘 要:人脸识别系统以人脸识别技术为核心,是一项新兴的生物识别技术,是当今比较热门的一项安全认证技术.它涉及人脸图像采集.人脸定位.人脸识别预处理.身份确认以及身份 ...

  5. 基于matlab的人脸识别算法

    基于matlab的人脸识别算法 1. 主成分的数目的选取 前已指出,设有p个随机变量,便有p个主成分.由于总方差不增不减,C1,C2等前几个综合变量的方差较大,而Cp,Cp-1等后几个综合变量的方差较 ...

  6. 基于matlab的人脸五官边缘检测方法,基于MATLAB的人脸识别系统的设计

    基于MATLAB的人脸识别系统的设计(论文12000字,外文翻译,参考程序) 摘要:本文基于MATLAB平台设计了一款简单的人脸识别系统,通过USB摄像头来采集图像,经过肤色方法进行人脸检测与定位,然 ...

  7. matlab:人脸识别

    matlab:人脸识别 Matlab人脸识别是一种利用计算机技术进行人脸识别的方法,其基本流程如下: 数据采集:使用数字相机或摄像机采集人脸图像,得到一系列图像数据. 图像预处理:对采集到的图像数据进 ...

  8. 人脸识别系统 matlab,基于MATLAB的人脸识别系统的设计

    基于MATLAB的人脸识别系统的设计(论文12000字,外文翻译,参考程序) 摘要:本文基于MATLAB平台设计了一款简单的人脸识别系统,通过USB摄像头来采集图像,经过肤色方法进行人脸检测与定位,然 ...

  9. 基于matlab人脸识别论文,毕业论文--基于MATLAB的人脸识别系统设计

    毕业论文--基于MATLAB的人脸识别系统设计 毕毕 业业 设设 计计 论论 文文 题 目 基于 MATLAB 的人脸识别系统设计 学 院 电气与信息工程学院 专 业 自动化 I 摘要 人脸识别是模式 ...

  10. matlab 识别调试,有关matlab的人脸识别程序,但调试是不成功

    有关matlab的人脸识别程序,但调试是不成功,求高手帮忙指点修改.在此先谢了 1.色彩空间转换 function[r,g]=rgb_RGB(Ori_Face) R=Ori_Face(:,:,1); ...

最新文章

  1. 淘宝装修:第一日 —— 图片轮播
  2. python运维开发之第十一天(RabbitMQ,redis)
  3. 【Consul】Consul架构-Gossip协议
  4. 关于java连接sqlserver2000 和sqlserver2005的初识
  5. GitHub的CI实践(xUnit / OpenCover /Appveyor / Coveralls.net)
  6. Oracle 存储过程错误之PLS-00201: 必须声明标识符
  7. 目前流行的装修风格_现在最流行的八大装修风格
  8. 蚂蚁金服 Service Mesh 落地实践与挑战|成都Service Mesh沙龙预告
  9. 心态很容易受别人影响_女人生宝宝也看年龄?这3个影响生育能力的因素,你得了解清楚...
  10. mysql-复习表的基本操作01
  11. 我TM快疯了,在博客园开博短短2个月,经历博客园数次故障。。。
  12. java 状态机_Java 数据持久化系列之池化技术
  13. JAVA性能优化权威指南 读书笔记(一)
  14. 利用Tampermonkey写脚本抢课
  15. 511遇见易语言分割文本
  16. 【java毕业设计】基于java+SSH+JSP的固定资产管理系统设计与实现(毕业论文+程序源码)——固定资产管理系统
  17. 【JZOJ A组】【NOIP2019模拟】最短路(tiring)
  18. 工训赛:从参赛到“弃赛”
  19. 品牌铸造,vivo踏入高端新境界
  20. 【优化训练】RePr:Improved Training of Convolutional Filters论文笔记

热门文章

  1. sklearn机器学习之分类预测算法应用
  2. SNMP:简单网络管理协议(一)
  3. php 程序设计代码教程
  4. [lammps教程]OVITO绘制原子运动轨迹线
  5. 平稳时间序列的相关概念
  6. 拉扎维对于简单CMOS电路的增益计算方法
  7. [C++] 导入FLTK几乎所有头文件
  8. pmp考试有题库么?有多少题?
  9. 那么如何成为优秀的机械工程师,如何提升自己的实力,有哪些值得注意和学习的呢?
  10. ADS仿真6_PA设计【未完成】