![基于PCA人臉識(shí)算法代碼_第1頁](http://file.renrendoc.com/FileRoot1/2018-6/2/32d39193-dd40-44be-bd91-163fae86179a/32d39193-dd40-44be-bd91-163fae86179a1.gif)
![基于PCA人臉識(shí)算法代碼_第2頁](http://file.renrendoc.com/FileRoot1/2018-6/2/32d39193-dd40-44be-bd91-163fae86179a/32d39193-dd40-44be-bd91-163fae86179a2.gif)
![基于PCA人臉識(shí)算法代碼_第3頁](http://file.renrendoc.com/FileRoot1/2018-6/2/32d39193-dd40-44be-bd91-163fae86179a/32d39193-dd40-44be-bd91-163fae86179a3.gif)
![基于PCA人臉識(shí)算法代碼_第4頁](http://file.renrendoc.com/FileRoot1/2018-6/2/32d39193-dd40-44be-bd91-163fae86179a/32d39193-dd40-44be-bd91-163fae86179a4.gif)
![基于PCA人臉識(shí)算法代碼_第5頁](http://file.renrendoc.com/FileRoot1/2018-6/2/32d39193-dd40-44be-bd91-163fae86179a/32d39193-dd40-44be-bd91-163fae86179a5.gif)
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1一種基于圖象分析的柜員機(jī) -人臉識(shí)別算法的研究代碼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; %全局變量,表示視頻信息的數(shù)據(jù)global mov;global nowpic;global saveindex;global faceindex;faceindex=1;saveindex=1;%初始化人臉識(shí)別界面7h = waitbar(0.1,檢測(cè)硬件,請(qǐng)等待.);global vidvid = videoinput(winvideo,1);vid_src=getselectedsource(vid);data = getsnapshot(vid);waitbar(0.5,h,初始化窗口,請(qǐng)等待.);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,初始化窗口,請(qǐng)等待.);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;%測(cè)試圖像和訓(xùn)練圖像,差距 a b = size(temp); InImage = reshape(temp,a*b,1);%將讀取的測(cè)試圖像 temp reshape 為只有 一 列 的矩陣 InImage Difference = double(InImage)-M; % Centered test image 將測(cè)試圖像和 m 作差,m 在前面講述過,為所有圖像灰度 reshape 后矩陣的平均值矩陣 ProjectedTestImage = Eigenfaces*Difference; % 特征臉和 differece 相乘得到 投影的 測(cè)試 圖像 %測(cè)試圖像特征向量 %differece 是只有 1 列的矩陣,特征臉是 N 列 N 行的矩陣,相乘得到只有 1 列的 ProjectedTestImage 矩陣 %識(shí)別過程,得到最后的識(shí)別圖 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 為對(duì)應(yīng)的第幾個(gè) % % % 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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司在職員工培訓(xùn)服務(wù)合同書
- 礦山企業(yè)安全生產(chǎn)許可證頒發(fā)與管理作業(yè)指導(dǎo)書
- 反擔(dān)保合同協(xié)議1
- 游戲美術(shù)設(shè)計(jì)制作實(shí)戰(zhàn)手冊(cè)作業(yè)指導(dǎo)書
- 針紡織品銷售購銷合同
- 小學(xué)二年級(jí)數(shù)學(xué)上冊(cè)口算
- 2025年紹興a2貨運(yùn)從業(yè)資格證模擬考試題
- 2024-2025學(xué)年高中語文專題一小說家想說些什么第1課在酒樓上學(xué)案蘇教版選修短篇小說蚜
- 七年級(jí)班級(jí)工作總結(jié)
- 四年級(jí)第一學(xué)期德育工作計(jì)劃
- 普外腹腔鏡手術(shù)護(hù)理常規(guī)
- 2024年全國(guó)職業(yè)院校技能大賽(礦井災(zāi)害應(yīng)急救援賽項(xiàng))考試題庫(含答案)
- 《預(yù)制高強(qiáng)混凝土風(fēng)電塔筒生產(chǎn)技術(shù)規(guī)程》文本附編制說明
- 2025江蘇南京市金陵飯店股份限公司招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- 監(jiān)控系統(tǒng)調(diào)試檢驗(yàn)批質(zhì)量驗(yàn)收記錄(新表)
- 錦州市主要環(huán)境問題論文
- 黃桃種植示范基地可行性研究報(bào)告
- 東風(fēng)4型內(nèi)燃機(jī)車檢修規(guī)程
- 藥品經(jīng)營(yíng)企業(yè)GSP計(jì)算機(jī)系統(tǒng)培訓(xùn)PPT課件
- 建筑工程冬期施工規(guī)程JGJT1042011
- 畢業(yè)論文市場(chǎng)營(yíng)銷畢業(yè)論文
評(píng)論
0/150
提交評(píng)論