码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2021-06-23 16:37:10      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:handles   image   人机交互   euler   cat   模式识别   pre   hold   let   

一、简介

人脸检测是人脸识别、人机交互、智能视觉监控等:工作的前提。近年来,在模式识别与计算机视觉领域,人脸检测已经成为一个受到普遍 重视、研究十分活跃的方向。本文针对复杂背景下的彩色正面人脸图像,将肤色分割、模板匹配与候选人脸图像块筛选结合起来,构建了人脸检测实验系统,并用自制的人脸图像数据库在该系统下进行了一系列的实验统计。本文首先介绍了人脸检测技术研究的背景和现状,阐明人脸检测技术发展的重要意义,对目前常用的一一些检测算法进行了总结,然后着重阐述了基于肤色分割和模板匹配验证的人脸检测算法。肤色是人脸重要特征,在通过肤色采样统计和聚类分析后,确立一种在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;

三、运行结果

技术图片

四、备注

版本:2014a
完整代码或代写加1564658423

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

标签:handles   image   人机交互   euler   cat   模式识别   pre   hold   let   

原文地址:https://www.cnblogs.com/homeofmatlab/p/14920497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!