




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1一种基于图象分析的柜员机 -人脸识别算法的研究代码1.EigenfaceCode.m:function m, A, Eigenfaces = EigenfaceCore(T)% Use Principle Component Analysis (PCA) to determine the most % discriminating features between images of faces.% Description: This function gets a 2D matrix, containing all training image vectors% and returns 3 outputs which are extracted from training database.% Argument: T - A 2D matrix, containing all 1D image vectors.% Suppose all P images in the training database % have the same size of MxN. So the length of 1D % column vectors is M*N and T will be a MNxP 2D matrix.% % Returns: m - (M*Nx1) Mean of the training database% Eigenfaces - (M*Nx(P-1) Eigen vectors of the covariance matrix of the training database% A - (M*NxP) Matrix of centered image vectors% See also: EIG% Original version by Amir Hossein Omidvarnia, October 2007% Email: aomidvarece.ut.ac.ir % Calculating the mean image m = mean(T,2); % Computing the average face image m = (1/P)*sum(Tjs) (j = 1 : P)Train_Number = size(T,2);2% Calculating the deviation of each image from mean imageA = ; for i = 1 : Train_Numbertemp = double(T(:,i) - m; % Computing the difference image for each image in the training set Ai = Ti - mA = A temp; % Merging all centered imagesend% Snapshot method of Eigenface methos% We know from linear algebra theory that for a PxQ matrix, the maximum% number of non-zero eigenvalues that the matrix can have is min(P-1,Q-1).% Since the number of training images (P) is usually less than the number% of pixels (M*N), the most non-zero eigenvalues that can be found are equal% to P-1. So we can calculate eigenvalues of A*A (a PxP matrix) instead of% A*A (a M*NxM*N matrix). It is clear that the dimensions of A*A is much% larger that A*A. So the dimensionality will decrease.L = A*A; % L is the surrogate of covariance matrix C=A*A.V D = eig(L); % Diagonal elements of D are the eigenvalues for both L=A*A and C=A*A.% Sorting and eliminating eigenvalues% All eigenvalues of matrix L are sorted and those who are less than a% specified threshold, are eliminated. So the number of non-zero% eigenvectors may be less than (P-1).3L_eig_vec = ;for i = 1 : size(V,2) if( D(i,i)1 )L_eig_vec = L_eig_vec V(:,i);endend% Calculating the eigenvectors of covariance matrix C% Eigenvectors of covariance matrix C (or so-called “Eigenfaces“)% can be recovered from Ls eiegnvectors.Eigenfaces = A * L_eig_vec; % A: centered image vectors42.pcafacesys.m:function varargout = pcafacesys(varargin)% PCAFACESYS M-file for pcafacesys.fig% PCAFACESYS, by itself, creates a new PCAFACESYS or raises the existing% singleton*.% H = PCAFACESYS returns the handle to a new PCAFACESYS or the handle to% the existing singleton*.% PCAFACESYS(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in PCAFACESYS.M with the given input arguments.% PCAFACESYS(Property,Value,.) creates a new PCAFACESYS or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before pcafacesys_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to pcafacesys_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose “GUI allows only one% instance to run (singleton)“.5% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help pcafacesys% Last Modified by GUIDE v2.5 03-May-2017 01:41:51% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, .gui_Singleton, gui_Singleton, .gui_OpeningFcn, pcafacesys_OpeningFcn, .gui_OutputFcn, pcafacesys_OutputFcn, .gui_LayoutFcn, , .gui_Callback, );if nargin endif nargoutvarargout1:nargout = gui_mainfcn(gui_State, varargin:);elsegui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before pcafacesys is made visible.function pcafacesys_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 pcafacesys (see VARARGIN)% Choose default command line output for pcafacesys6handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes pcafacesys wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = pcafacesys_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout1 = handles.output;% - Executes on button press in load_btn.function load_btn_Callback(hObject, eventdata, handles)% hObject handle to load_btn (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global filename; %全局变量,文件名称global pname; %全局变量,文件路径global fname; %全局变量,文件名字global info; %全局变量,表示 avi 文件的信息global videodata; %全局变量,表示视频信息的数据global mov;global nowpic;global saveindex;global faceindex;faceindex=1;saveindex=1;%初始化人脸识别界面7h = waitbar(0.1,检测硬件,请等待.);global vidvid = videoinput(winvideo,1);vid_src=getselectedsource(vid);data = getsnapshot(vid);waitbar(0.5,h,初始化窗口,请等待.);set(vid,TriggerRepeat,Inf);set(vid,FramesPerTrigger,1);set(vid,FrameGrabInterval,1);vidRes = get(vid, VideoResolution);nBands = get(vid, NumberOfBands);% % % axes(handles.axes1);% Display the video data in your GUI.waitbar(1.0,h,初始化窗口,请等待.);close(h);% % % hImage = image( zeros(vidRes(2), vidRes(1), nBands) );% % % % % axes(handles.src_axes);% % % preview(vid, hImage);hImage=image(zeros(vidRes(2), vidRes(1), nBands);preview(vid,hImage);% - Executes on button press in 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 m;global A;global Eigenfaces;global croppic;global trainpic;global namecode;8global train_Y;global vector;global C;global gamma;global multiSVMStruct;global mov;global nowpic;global namecode; global M;global Train_Number;global ProjectedImages;global trainpicture;temp = rgb2gray(croppic);resizepic=imresize(temp,300,200);temp=resizepic;%测试图像和训练图像,差距 a b = size(temp); InImage = reshape(temp,a*b,1);%将读取的测试图像 temp reshape 为只有 一 列 的矩阵 InImage Difference = double(InImage)-M; % Centered test image 将测试图像和 m 作差,m 在前面讲述过,为所有图像灰度 reshape 后矩阵的平均值矩阵 ProjectedTestImage = Eigenfaces*Difference; % 特征脸和 differece 相乘得到 投影的 测试 图像 %测试图像特征向量 %differece 是只有 1 列的矩阵,特征脸是 N 列 N 行的矩阵,相乘得到只有 1 列的 ProjectedTestImage 矩阵 %识别过程,得到最后的识别图 Euc_dist = ; for i = 1 : Train_Number 9q = ProjectedImages(:,i); %表示该投影的图像矩阵 第 i 列 的所有元素,定义为 q temp = ( norm( ProjectedTestImage - q ) )2; %只有 1 列的ProjectedTestImage 矩阵与投影的图像矩阵 第 i 列作差,平方,得矩阵 temp %算法Euc_dist = Euc_dist temp; % 合并为 Euc_dist 矩阵 end Euc_dist_min , Recognized_index = min(Euc_dist);%取得 Euc_dist 矩阵最小值 Euc_dist_min %Recognized_index 为对应的第几个 % % % p= int2str(Recognized_index) % % % OutputName = strcat(pic,p,.bmp); A=resizepic; B=trainpictureRecognized_index;A=A-mean2(A);B=B-mean2(B); similar = sum(sum(A.*B)/sqrt(sum(sum(A.*A)*sum(sum(B.*B);%相似度算法,similar 为最后的相似度值 if similar0.8 set(handles.result_edit,string,不是本人 );%clear();elseset(handles.result_edit,string,本人 );%clear();endfunction result_edit_Callback(hObject, eventdata, handles)% hObject handle to result_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)10% Hints: get(hObject,String) returns contents of result_edit as text% str2double(get(hObj
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 摔跤课件简介
- 摄影社团教学课件
- 江苏省南京市联合体2024-2025学年八年级下学期期末语文试题(解析版)
- 摄影学员基础知识培训课件
- 数控技术试题及答案文库
- 2025合同纠纷频发:恶意诉讼成职场新现象
- 摄像设备基础知识培训课件
- 公司销售培训产品知识课件
- 公司财务知识培训通知课件
- 公司财务知识培训制度课件
- (2025)水利安全员c证考试题库及参考答案
- 一线员工执行力培训内容
- 民营中医院开办可行性报告
- 经皮冠状动脉介入治疗指南2025
- 主动脉瓣置换护理常规
- 船舶公司内务管理制度
- 食品供应链内部管理制度
- 护理职业素养课件
- 2025年云南中考数学试卷真题解读及复习备考指导
- 数字身份认证伦理-洞察及研究
- 生态旅游承载力研究-洞察及研究
评论
0/150
提交评论