1 简介
人脸检测是人脸分析的首要环节,其处理的问题是确认图像中是否存在人脸,如果存在则对人脸进行定位。人脸检测的应用领域相当广泛,是实现机器智能化的重要步骤之一。AdaBoost算法是1995年提出的一种快速人脸检测算法,是人脸检测领域里程碑式的进步,这种算法根据弱学习的反馈,适应性地调整假设的错误率,使在效率不降低的情况下,检测正确率得到了很大的提高。本文对影响AdaBoost人脸检测训练算法速度的至关重要的两方面:Haar特征和积分图的概念和理论进行了仔细的阐明。同时给出了AdaBoost的算法,并深入探讨了其中的一些关键问题——弱学习器的构造、选取等问题。本文还将AdaBoost训练出来的多个强分类器连接在一起,形成同时具备高检测率和低误识率的级联分类器——Haar分类器。最后用Haar分类器实现人脸检测并通过检测五官来检验检测结果。
图像目标的检测与识别向来是机器视觉领域的重要研究内容。其中,人脸图像信息的处理技术一直都是模式识别与机器视觉研究领域内关注的重要问题,是现阶段基于生物特征的身份识别技术的重要组成部分之一。作为人脸信息处理中的一项关键技术,人脸检测的应用背景已经远远超出了人脸识别系统的范畴,在身份验证、基于内容的图像检索、数字视频处理、视觉监测等方面都有着重要的应用价值。
人脸是一种完全开放的信息源,是图像和视频中最重要的视觉图像之一。通过人脸可以得到一个人的性别、年龄、表情和身份等个体信息。人脸分析的相关研究希望用户的身份、状态和意图的信息能够从图像中提取出来,然后由计算依此做出反应(比如通过观察用户脸部表情来分析心情并进行相应反应)。
人脸检测是指在输入图像中确定所有存在的人脸的位置、大小的过程。人脸识别或辨认、人脸定位以及人脸追踪等都与人脸检测密切相关。
早期的人脸识别算法都是在假设已经得到了一个正面人脸或者假设人脸很容易获得的前提下进行的,但是随着人脸分析应用范围的不断扩大和开发实际系统需求的不断提高,这种假设下的研究不再能满足需求。人脸检测开始作为独立的研究内容发展起来。
近年来出现了大量的人脸检测方法,其中Paul Viola和Michael Jones于2001年提出的Adaboost算法是第一个实时的人脸检测算法,从根本上解决了检测的速度问题,同时具有较好的识别效果。
本文研究AdaBoost人脸检测方法的训练流程,研究了Adaboost算法的实现步骤,设计并实现基于Haar分类器的人脸检测系统,并通过检测五官来检验检测结果。
2 部分代码
function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to 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 gui
% Last Modified by GUIDE v2.5 19-Dec-2016 02:28:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_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 gui is made visible.
function 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 gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- 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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% 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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% 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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% 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 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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% Hint: place code in OpeningFcn to populate axes3
% --- Executes during object creation, after setting all properties.
function axes5_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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% Hint: place code in OpeningFcn to populate axes3
% --- Executes during object creation, after setting all properties.
function axes6_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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% Hint: place code in OpeningFcn to populate axes3
% --- Executes during object creation, after setting all properties.
function axes7_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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% Hint: place code in OpeningFcn to populate axes3
function axes8_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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% Hint: place code in OpeningFcn to populate axes3
function axes9_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(hObject,'xTick',[]); % 去掉坐标轴
set(hObject,'ytick',[]); % 去掉坐标轴
set(hObject,'box','on'); % 去掉坐标轴
% Hint: place code in OpeningFcn to populate axes3
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 during object creation, after setting all properties.
function pushbutton3_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
3 仿真结果
4 参考文献
[1]刘子源, 蒋承志. 基于OpenCV和Haar特征分类器的图像人数检测[J]. 辽宁科技大学学报, 2011(04):50-54.
部分理论引用网络文献,若有侵权联系博主删除。
5 MATLAB代码与数据下载地址
见博客主页