基于MATLAB的人脸识别系统

一、课题背景

自70年代以来.随着人工智能技术的兴起.以及人类视觉研究的进展.人们逐渐对人脸图像的机器识别投入很大的热情,并形成了一个人脸图像识别研究领域,.这一领域除了它的重大理论价值外,也极具实用价值。

在进行人工智能的研究中,人们一直想做的事情就是让机器具有像人类一样的思考能力,以及识别事物、处理事物的能力,因此从解剖学、心理学、行为感知学等各个角度来探求人类的思维机制、以及感知事物、处理事物的机制,并努力将这些机制用于实践,如各种智能机器人的研制。人脸图像的机器识别研究就是在这种背景下兴起的,因为人们发现许多对于人类而言可以轻易做到的事情,而让机器来实现却很难,如人脸图像的识别,语音识别,自然语言理解等。如果能够开发出具有像人类一样的机器识别机制,就能够逐步地了解人类是如何存储信息,并进行处理的,从而最终了解人类的思维机制。

同时,进行人脸图像识别研究也具有很大的使用价依。如同人的指纹一样,人脸也具有唯一性,也可用来鉴别一个人的身份。现在己有实用的计算机自动指纹识别系统面世,并在安检等部门得到应用,但还没有通用成熟的人脸自动识别系统出现。人脸图像的自动识别系统较之指纹识别系统、DNA鉴定等更具方便性,因为它取样方便,可以不接触目标就进行识别,从而开发研究的实际意义更大。并且与指纹图像不同的是,人脸图像受很多因素的干扰:人脸表情的多样性;以及外在的成像过程中的光照,图像尺寸,旋转,姿势变化等。使得同一个人,在不同的环境下拍摄所得到的人脸图像不同,有时更会有很大的差别,给识别带来很大难度。因此在各种干扰条件下实现人脸图像的识别,也就更具有挑战性。

国外对于人脸图像识别的研究较早,现己有实用系统面世,只是对于成像条件要求较苛刻,应用范围也就较窄,国内也有许多科研机构从事这方而的研究,并己取得许多成果。

二、算法流程


人脸图像获取

人脸检测

特征提取

人脸识别

图2.1 人脸识别系统一般框架

(1)人脸图像的获取

一般来说,图像的获取都是通过摄像头摄取,但摄取的图像可以是真人,也可以是人脸的图片或者为了相对简单,可以不考虑通过摄像头来摄取头像,而是直接给定要识别的图像。

(2)人脸的检测

人脸检测的任务是判断静态图像中是否存在人脸。若存在人脸,给出其在图像中的坐标位置、人脸区域大小等信息。而人脸跟踪则需要进一步输出所检测到的人脸位置、大小等状态随时间的连续变化情况。

(3)特征提取

通过人脸特征点的检测与标定可以确定人脸图像中显著特征点的位置(如眼睛、眉毛、鼻子、嘴巴等器官),同时还可以得到这些器官及其面部轮廓的形状信息的描述。

根据人脸特征点检测与标定的结果,通过某些运算得到人脸特征的描述(这些特征包括:全局特征和局部特征,显式特征和统计特征等)。

(4)基于人脸图像比对的身份识别

即人脸识别(Face Identification)问题。通过将输入人脸图像与人脸数据库中的所有已知原型人脸图像计算相似度并对其排序来给出输入人脸的身份信息。这包括两类识别问题:一类是闭集(Close Set)人脸识别问题,即假定输入的人脸一定是人脸库中的某个个体;另一类是开集(Open Set)识别,即首先要对输入人脸是否在已知人脸库中做出判断,如果是,则给出其身份。

(5)基于人脸图像比对的身份验证

即人脸确认(Face Verification)问题。系统在输入人脸图像的同时输入一个用户宣称的该人脸的身份信息,系统要对该输入人脸图像的身份与宣称的身份是否相符作出判断。

三、运行效果

1、人脸定位


690a2c118a18749a9dfd120e44abbca8.png

990dd7c78e805e7356a8870126c7d67c.png



fbddc70654fa970fe03ec59181ccd9cd.png


f0c9f0c01811fb123c61afb98174b317.png


2 人脸识别


84e8d4f0d82bc1f04d303107063c273f.png
图4.1 用户界面

617703eae8bde2f2bdff68a53f0bcc50.png
图4.2 实现结果


四、源码
function varargout = FR_Processed_histogram(varargin)
%这种算法是基于直方图处理的方法
%The histogram of image is calculated and then bin formation is done on the
%basis of mean of successive graylevels frequencies. The training is done on odd images of 40 subjects (200 images out of 400 images) 
 
%The results of the implemented algorithm is 99.75 (recognition fails on image number 4 of subject 17)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FR_Processed_histogram_OpeningFcn, ...
                   'gui_OutputFcn',  @FR_Processed_histogram_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
 
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
 
%--------------------------------------------------------------------------
% --- Executes just before FR_Processed_histogram is made visible.
function FR_Processed_histogram_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 FR_Processed_histogram (see VARARGIN)
 
% Choose default command line output for FR_Processed_histogram
handles.output = hObject;
 
% Update handles structure
guidata(hObject, handles);
 
% UIWAIT makes FR_Processed_histogram wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global total_sub train_img sub_img max_hist_level bin_num form_bin_num;
 
total_sub = 40;
train_img = 200;
sub_img = 10;
max_hist_level = 256;
bin_num = 9;
form_bin_num = 29;
%--------------------------------------------------------------------------
% --- Outputs from this function are returned to the command line.
function varargout = FR_Processed_histogram_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 structure
varargout{1} = handles.output;
 
%--------------------------------------------------------------------------
% --- Executes on button press in train_button.  
function train_button_Callback(hObject, eventdata, handles)
% hObject    handle to train_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
global train_processed_bin;
global total_sub train_img sub_img max_hist_level bin_num form_bin_num;
 
train_processed_bin(form_bin_num,train_img) = 0;
K = 1;
train_hist_img = zeros(max_hist_level, train_img);
 
for Z=1:1:total_sub 
  for X=1:2:sub_img    %%%train on odd number of images of each subject
 
    I = imread( strcat('ORL\S',int2str(Z),'\',int2str(X),'.bmp') );        
    [rows cols] = size(I);
 
    for i=1:1:rows
       for j=1:1:cols
           if( I(i,j) == 0 )
               train_hist_img(max_hist_level, K) =  train_hist_img(max_hist_level, K) + 1;                            
           else
               train_hist_img(I(i,j), K) = train_hist_img(I(i,j), K) + 1;                         
           end
       end   
    end   
     K = K + 1;        
  end  
 end  
 
[r c] = size(train_hist_img);
sum = 0;
for i=1:1:c
    K = 1;
   for j=1:1:r        
        if( (mod(j,bin_num)) == 0 )
            sum = sum + train_hist_img(j,i);            
            train_processed_bin(K,i) = sum/bin_num;
            K = K + 1;
            sum = 0;
        else
            sum = sum + train_hist_img(j,i);            
        end
    end
    train_processed_bin(K,i) = sum/bin_num;
end
 
display ('Training Done')
save 'train'  train_processed_bin;
 
%--------------------------------------------------------------------------
% --- Executes on button press in Testing_button.    
function Testing_button_Callback(hObject, eventdata, handles)
% hObject    handle to Testing_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global train_img max_hist_level bin_num form_bin_num;
global train_processed_bin;
global filename pathname I
 
load 'train'
test_hist_img(max_hist_level) = 0;
test_processed_bin(form_bin_num) = 0;
 
 
 [rows cols] = size(I);
 
    for i=1:1:rows
       for j=1:1:cols
           if( I(i,j) == 0 )
               test_hist_img(max_hist_level) =  test_hist_img(max_hist_level) + 1;                            
           else
               test_hist_img(I(i,j)) = test_hist_img(I(i,j)) + 1;                         
           end
       end   
    end   
 
  [r c] = size(test_hist_img);
  sum = 0;
 
    K = 1;
    for j=1:1:c        
        if( (mod(j,bin_num)) == 0 )
            sum = sum + test_hist_img(j);            
            test_processed_bin(K) = sum/bin_num;
            K = K + 1;
            sum = 0;
        else
            sum = sum + test_hist_img(j);            
        end
    end
 
 test_processed_bin(K) = sum/bin_num;
 
sum = 0;
K = 1;
 
    for y=1:1:train_img
        for z=1:1:form_bin_num        
          sum = sum + abs( test_processed_bin(z) - train_processed_bin(z,y) );  
        end         
        img_bin_hist_sum(K,1) = sum;
        sum = 0;
        K = K + 1;
    end
 
    [temp M] = min(img_bin_hist_sum);
    M = ceil(M/5);
    getString_start=strfind(pathname,'S');
    getString_start=getString_start(end)+1;
    getString_end=strfind(pathname,'\');
    getString_end=getString_end(end)-1;
    subjectindex=str2num(pathname(getString_start:getString_end));
 
    if (subjectindex == M)
      axes (handles.axes3)
      %image no: 5 is shown for visualization purpose
      imshow(imread(STRCAT('ORL\S',num2str(M),'\5.bmp')))    
      msgbox ( 'Correctly Recognized');
    else
     display ([ 'Error==>  Testing Image of Subject >>' num2str(subjectindex) '  matches with the image of subject >> '  num2str(M)])
     axes (handles.axes3)
     %image no: 5 is shown for visualization purpose
     imshow(imread(STRCAT('ORL\S',num2str(M),'\5.bmp')))    
     msgbox ( 'Incorrectly Recognized');
    end
 
display('Testing Done')
%--------------------------------------------------------------------------
function box_Callback(hObject, eventdata, handles)
% hObject    handle to box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of box as text
%        str2double(get(hObject,'String')) returns contents of box as a double
 
%--------------------------------------------------------------------------
% --- Executes during object creation, after setting all properties.
function box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%--------------------------------------------------------------------------
% --- Executes on button press in Input_Image_button.
function Input_Image_button_Callback(hObject, eventdata, handles)
% hObject    handle to Input_Image_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename pathname I
[filename, pathname] = uigetfile('*.bmp', 'Test Image');
axes(handles.axes1)
imgpath=STRCAT(pathname,filename);
 
I = imread(imgpath);
imshow(I)
 
%--------------------------------------------------------------------------
% --- 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
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你的matlab大师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值