资源简介
人脸识别中检测人脸眼睛的状态,基于matlab的,简单易懂

代码片段和文件信息
clc;
clear all;
%------------------读入待识别的人脸图像------------------------
[filename pathname] = uigetfile( ...
{‘*.bmp;*.jpg;*.png;*.jpeg‘ ‘Image Files (*.bmp*.jpg*.png*.jpeg)‘; ...
‘*.*‘ ‘All Files (*.*)‘} ...
‘Pick an image‘);
if isequal(filename0)||isequal(pathname0)
return;
end;
fpath=[pathname filename];
RGB=imread(fpath);
YCbCr=rgb2ycbcr(RGB);%将rgb图像转为YCbCr图像
[HW]=size(rgb2gray(RGB));
%------------------利用肤色来提取人脸区--------------------------
M=[117.4361;156.5599];
C=[160.130112.1430;12.1430299.4574]; %见文献
P=zeros(HW);
PM=0;
x=zeros(21); %x=[CbCr]‘转置
for i=1:H
for j=1:W
x(1)=YCbCr(ij2);
x(2)=YCbCr(ij3);
P(ij)=exp(-0.5*(x-M)‘/C*(x-M));%相似度计算
if P(ij)>PM
PM=P(ij);
end
end
end
P=P/PM; %归一化
%---------------图像二值化---------------------------
thr=0.6:-0.05:0.10;
len=length(thr);
nch=zeros(len-11);
num=zeros(len);
for k=1:len
thresh=thr(k); %设定可能的阈值
num(k)=sum(sum(P>thresh));
if k>1
nch(k-1)=num(k)-num(k-1);
end
end
[minnchindex]=min(nch);
thresh=thr(index+1);%确定阈值
I=P>thresh; %二值化处理
subplot(221)imshow(I)%I为二值化后的图像
%-------------------直方图,即投影积分--------------------------
shp=sum(I2);%人脸水平投影,即横向,来确定人脸的高度
shp=shp‘;
len=length(shp);
y=1:len;
hold on
subplot(221)
chz=sum(I); %人脸垂直投影,即竖直方向来确定人脸的宽度
%subplot(222)
plot(shpy);
%subplot(222)
plot(chz);
subplot(222)
plot(shpy);
subplot(222)
plot(chz);
%%%%利用chz确定左右边界,左边界是峰值的0.2倍,右边界是峰值的0.3倍
[max_chzindex]=max(chz);
i=index;
while i>0
i=i-1;
if chz(i)<0.2*max_chz;
L=i;
break;
end
end
j=index;
while j j=j+1;
if chz(j)<0.3*max_chz;
R=j;
break;
end
end
%%%%%%%%达到人脸宽度一半的起始位置确定为人脸框的上边界
newpface=I(:L:R);
newshp=sum(newpface2);
i=0;
while i i=i+1;
if newshp(i)>0.5*(R-L);
T=i; %%%上边界
break;
end
end
B=T+1.4*(R-L); %下边界1.5
if B>H
B=H;
else
B=floor(B);
end;
subplot(224)imshow(RGB)
hold on;
subplot(224);
plot([L L][T B]‘Linewidth‘2‘color‘‘red‘);
plot([R R][T B]‘Linewidth‘2‘color‘‘red‘);
plot([L R][B B]‘Linewidth‘2‘color‘‘red‘);
plot([L R][T T]‘Linewidth‘2‘color‘‘red‘);
face=RGB(T:BL:R:);
figure(2);
imshow(face);
%------------------确定眼睛y轴位置----------------------------
faceb=I(T:BL:R);%脸部的二值化图像,该二值化图像是以肤色为阈值的
figure(3)
subplot(221)imshow(faceb);
shp=sum(faceb2);%人脸水平投影,即横向,来确定人脸的高度
shp=shp‘;
len=length(shp);
y=1:len;
chz=sum(faceb); %人脸垂直投影,即竖直方向来确定人脸的宽度
hold on
%subplot(222)
shp=smooth(shp30‘loess‘);%对数据进行平滑处理
chz=smooth(chz30‘loess‘);
plot(shpy);
%subplot(223)
plot(chz);
subplot(222)
plot(shpy);
subplot(223)
plot(chz);
indexmin=find(diff(sign(diff(shp)))==2)+1; %求极小值对应位置
midface=len/2-5;%人脸的水平中心位置
nummin=length(indexmin);%极小值个数
indexpf=find(indexmin eye=indexmin(indexpf(end));
eyebr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6380 2013-05-20 17:26 客户\ycbcr.m
文件 5651 2013-05-20 13:34 客户\za.fig
文件 9844 2013-05-20 13:48 客户\za.m
文件 3584 2013-05-20 13:34 客户\za_activex1
文件 3584 2013-05-20 13:34 客户\za_activex2
文件 710656 2013-05-20 19:17 客户\项目验收程序说明.doc
目录 0 2013-05-21 21:45 客户
----------- --------- ---------- ----- ----
739699 7
相关资源
- 串行级联cpm系统MATLAB仿真
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
评论
共有 条评论