【人脸识别】基于matlab GUI肤色人脸识别定位【含Matlab源码 674期】

举报
海神之光 发表于 2022/05/29 03:15:57 2022/05/29
【摘要】 一、简介 人脸检测是人脸识别、人机交互、智能视觉监控等:工作的前提。近年来,在模式识别与计算机视觉领域,人脸检测已经成为一个受到普遍 重视、研究十分活跃的方向。本文针对复杂背景下的彩色正面人脸图像,将肤...

一、简介

人脸检测是人脸识别、人机交互、智能视觉监控等:工作的前提。近年来,在模式识别与计算机视觉领域,人脸检测已经成为一个受到普遍 重视、研究十分活跃的方向。本文针对复杂背景下的彩色正面人脸图像,将肤色分割、模板匹配与候选人脸图像块筛选结合起来,构建了人脸检测实验系统,并用自制的人脸图像数据库在该系统下进行了一系列的实验统计。本文首先介绍了人脸检测技术研究的背景和现状,阐明人脸检测技术发展的重要意义,对目前常用的一一些检测算法进行了总结,然后着重阐述了基于肤色分割和模板匹配验证的人脸检测算法。肤色是人脸重要特征,在通过肤色采样统计和聚类分析后,确立一种在YCbCr空间下的基于高斯模型的肤色分割方法。在YCbCr色彩空间中建立肤色分布的高斯模型,得到肤色概率似然图像,在最佳动态阈值选取算法下完成肤色区域的分割。采用 数学形态学和一些先验知识对所得到的肤色区域进行人脸特征筛选,进–步剔除非人脸肤色区域,减少候选人脸数量,简化后续检测过程的处理。本文使用平均模板匹配方法对候选人脸进行确认,并针对图像中的人脸通常有一定角度旋转和尺寸大小不确定的问题,通过计算候选人脸图像块的偏转角度和面积,并以此调整模板,优化模板配准,提高模板匹配的准确性,同时避免使用多尺度模板进行多次匹配运算,提高算法效率。提出利用候选人脸图像区域和模板质心作为配准的原点,抑制人脸图像噪声的干扰。最后构建了基于肤色分割和模板验证的人脸检测试验系统,并对该系统采用自制人脸图像数据库进行测试。实验结果表明,系统算法是有效的,具有较高的检测性能和低的误判率。

二、部分源代码

function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 19-May-2020 15:25:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @untitled_OutputFcn, ...
    'gui_OutputFcn',  @untitled_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 untitled is made visible.
function untitled_OutputFcn(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 untitled (see VARARGIN)

% Choose default command line output for untitled
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
%-------------------------------------- pushbutton1_Callback(回调函数)
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global im imycbcr skin1 skin2 lpf %----------------宣布为全域变量
% 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)
if get (gcbo, 'Value' ) ==1;
    im=imread('10.jpg' ) ; %------------------------------读入彩色图像
    axes(handles.axes1)
    set(handles.axes1, 'XMinorTick' , 'on' ) %-------------嵌入Axes(1) 回调函数
    imshow(im) ; %------------------------------显示彩色图像
else
    imformats
end
% Hint: get(hObject, ' Value' ) returns push state of togglebutton1
%-------------------------------------- pushbutton2_Callback(回调函数)
% --- 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)
global im imycbcr skin1 skin2 lpf %------
    cr = filter2(lpf, cr) ;
    cr = reshape(cr, 1, prod(size(cr) ) ) ;
    bmean = mean(cb) ; %--------------------------------求平均值
    rmean = mean(cr) ;
    brcov = cov(cb, cr) ;
    skin1 = zeros(dim(1) , dim(2) ) ;
    for i = 1: dim(1)
        for j = 1: dim(2)
            cb = double(imycbcr(i, j, 2) ) ;
            cr = double(imycbcr(i, j, 3) ) ;
            x =[(cb-bmean);(cr-rmean)] ;
            skin1(i,j) = exp(-0.5*x'*inv(brcov)*x) ; %---------------------------------计算任意像素为皮肤的概率
      
    skin1 = skin1./max(max(skin1) ) ;
    axes(handles. axes3)
    set(handles. axes3, 'XMinorTick' , 'on' ) %-------------嵌入Axes(3) 回调函数
    imshow(skin1) ; %------------------------------显示皮肤概率图像
else
    imformats
end
% Hint: get(hObject, ' Value' ) returns push state of pushbutton3
%-------------------------------------- pushbutton4_Callback(回调函数)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im imycbcr skin1 skin2 lpf %----------------: 0.05
        skin2 = zeros(size(skin1,1),size(skin1,2)) ;
        skin2(find(skin1>threshold)) = 1;
        change = sum(sum(skin2 - previousSkin2) ) ;
        changelist = [changelist change] ;
        previousSkin2 = skin2;
    end
    %----------------------------------找出最佳门限值
    [C, I] = min(changelist) ;
    optimalThreshold = (7-I) *0.1;
    skin2 = ones(size(skin1,1),size(skin1,2)) ;
    skin2(find(skin1>optimalThreshold))= 0;
    skin2 = filter2(lpf, skin2) ; %------------------------中值滤波
    axes(handles.axes5)
    set(handles. axes5, 'XMinorTick','on' ) %-------------嵌入Axes(4) 回调函数
    imshow(skin2); %------------------------------显示皮肤二值化图像
else
    imformats
end
% Hint: get(hObject, ' Value' ) returns push state of pushbutton4
%-------------------------------------- pushbutton5_Callback(回调函数)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im imycbcr skin1 skin2 lpf %----------------宣布为全域变量
if get (gcbo, 'Value' ) ==1;
    sumarea = bwarea(skin2) ; %-----------计算对象的总面积, 为利用面积进行判别做准备
    [L,numobj] =bwlabel(skin2, 8) ;
    avearea = sumarea/numobj; %-----------计算出对象的平均面积
    A = zeros(4, numobj) ;%179
    n = 1;
   
        % ------------------------获得一副只包含该区域的图像, 让图像其他区域为黑色
        bwsegment = bwselect(skin2, y, x, 8) ;
        % --------------------- 计算出该区域内分割块的数目
        [L, numobjs] = bwlabel(bwsegment, 4) ;
        % ---------------------------------得到区域孔的数目
        numfeatures = bweuler(bwsegment, 4) ;
        numholes = 1 - numfeatures;
        % --------------------------------扫描得出区域坐标
        top = -1;
        buttom =-1;
        left = -1;
        right = -1;
        dim=size(bwsegment);
        for i=1:dim(1)
            for j=1:dim(2)
                if(bwsegment(i,j) ~= 0)
                    top=i;
                    break;
                end;
            end;
            if (top ~= -1) break; end;
        end;

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/115409562

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。