clear;
%读入图象
imgSrc=imread('02.bmp');
[imSrcH,imSrcW]=size(imgSrc);
subplot(2,2,1); %画出原图像
imshow(imgSrc(10:imSrcH-10,5:imSrcW-5)); %剪切图像
%眼睛定位
imMidW=imSrcW/2;
hEye=uint8(imSrcH*0.4); %认为眼睛区域高度占人脸的0.4左右
hEye=double(hEye);
imgleft=imgSrc(10:hEye,5:imMidW);
imgright=imgSrc(10:hEye,imMidW+5:imSrcW);
[leftH,leftW]=size(imgleft);
[leftebIndex,lefteyeIndex,leftb,leftc,leftminW,leftmaxW]=position(imgleft);
%左眼定位
[rightebIndex,righteyeIndex,rightb,rightc,rightminW,rightmaxW]=position(imgright); %右眼定位
lefty1=leftb(1)-18+max(leftebIndex)+max(leftebIndex)-8;
lefty2=leftc(1)-18+max(leftebIndex)+max(leftebIndex)-8;
righty1=rightb(1)-18+max(rightebIndex)+max(rightebIndex)-8;
righty2=rightc(1)-18+max(rightebIndex)+max(rightebIndex)-8;
subplot(2,2,1);
hold on
plot(lefteyeIndex,max(leftebIndex),'r.');
subplot(2,2,1);
hold on
plot(imMidW+righteyeIndex,max(rightebIndex),'r.'); %眼睛位置显示
hold on
plot([leftminW+lefteyeIndex-22+2 leftmaxW+lefteyeIndex-22+2],[lefty1+3 lefty2+3],'r.');
hold on
plot([imMidW+rightminW+righteyeIndex-15+2 imMidW+rightmaxW+righteyeIndex-15+2],[righty1+3 righty2+3],'r.');
%鼻孔定位
eyey=max(max(leftebIndex),max(rightebIndex))+25;
eyemid=uint8((lefteyeIndex+imMidW+righteyeIndex)/2);
eyemid=double(eyemid);
hNose=eyey+40; %选定鼻子区域高度为40
leftnosefile=imgSrc(eyey:hNose-8,5:eyemid);
subplot(2,2,3);
imshow(leftnosefile);
leftnoseyvector = mean(leftnosefile,2);
leftnoseyvector = leftnoseyvector/max(leftnoseyvector); %归一化
leftnoseyvector=vectorsmooth(leftnoseyvector,3); %向量平滑
leftnoseyvector=leftnoseyvector/max(leftnoseyvector);
[leftyval,leftyIndex]=findmins(leftnoseyvector,1); %寻找谷值
leftnosexvector = mean(leftnosefile);
leftnosexvector=leftnosexvector/max(leftnosexvector);
leftnosexvector=vectorsmooth(leftnosexvector,3);
leftnosexvector=leftnosexvector/max(leftnosexvector);
[leftxVal,leftxIndex]=findmins(leftnosexvector,2);
nosex1=max(leftxIndex);
nosey1=max(leftyIndex)+eyey-10;
rightnosefile=imgSrc(eyey:hNose-8,eyemid:imSrcW-8);
subplot(2,2,4);
imshow(rightnosefile);
rightnoseyvector = mean(rightnosefile,2);
rightnoseyvector = rightnoseyvector/max(rightnoseyvector);
rightyVector=vectorsmooth(rightnoseyvector,3);
rightyVector=rightyVector/max(rightyVector);
[rightyval,rightyIndex]=findmins(rightyVector,1);
rightnosexvector = mean(rightnosefile);
rightnosexvector=rightnosexvector/max(rightnosexvector);
rightnosexvector=vectorsmooth(rightnosexvector,3);
rightnosexvector=rightnosexvector/max(rightnosexvector);
[rightxVal,rightxIndex]=findmins(rightnosexvector,2);
nosex2=eyemid+min(rightxIndex);
nosey2=min(rightyIndex)+eyey-10;
subplot(221);
hold on
plot([nosex1 nosex2],[nosey1 nosey2],'r.'); %显示鼻子定位结果
%嘴角定位
nosey=max(nosey1,nosey2)+20;
hMouth=uint8(imSrcH*0.85); %认为mouth区域高度占人脸的0.6-0.9左右
hMouth=double(hMouth);
hMouth=nosey+30;
mouthfile=imgSrc(nosey:hMouth-10,eyemid-30:eyemid+40); %定出嘴巴角区域
subplot(2,2,2);
imshow(mouthfile);
%suan算子法定为嘴角
[MHeight,MWidth]=size(mouthfile);
MouthIntegral = sum(mouthfile,2);
MouthIntegral = MouthIntegral/max(MouthIntegral);
MouthIntegral=vectorsmooth(MouthIntegral,3);
MouthIntegral=MouthIntegral/max(MouthIntegral);
[mVal,mIndex]=findmins(MouthIntegral,1);
Copy=zeros(MHeight,MWidth);
%SUSAN算子对嘴巴区域进行滤波
c=0;
for i=4:MHeight-3
for j=4:MWidth-3
for m=-3:3
for n=-3:3
if (abs(m)+abs(n)<=4)
if abs(double(mouthfile(i+m,j+n))-double(mouthfile(i,j)))<=20
c=c+exp(-double((double(mouthfile(i+m,j+n))-double(mouthfile(i,j)))/15)^6);
end
end
end
end
Copy(i,j)=c;
c=0;
end
end
g=0.58*max(max(Copy));
for i=1:MHeight-6
for j=1:MWidth-6
if Copy(i+3,j+3)<g
Copy1(i,j)=1;
else Copy1(i,j)=0;
end
end
end
[eyeH,eyeW]=find(Copy1==1); %Copy为滤波后的二值图像
mouthminW=min(eyeW);
mouthmaxW=max(eyeW);
minP=find(eyeW==mouthminW);
maxP=find(eyeW==mouthmaxW);
mouthx1=mouthminW+eyemid-30;
mouthx2=mouthmaxW+eyemid-30;
mouthb=sort(eyeH(minP)+20-max(mIndex));
mouthc=sort(eyeH(maxP)+20-max(mIndex));
mouthy1=mouthb(1)-20+max(mIndex)+nosey-5;
mouthy2=mouthc(1)-20+max(mIndex)+nosey-5;
subplot(2,2,1);
hold on
plot( [mouthx1 mouthx2],[mouthy1 mouthy2] ,'r.'); %显示嘴角定位结果
matlab_利用人脸的灰度值的不同可以高效识别人脸区域以及定位的功能,以及可以识别非人脸
版权申诉
28 浏览量
2022-07-14
08:12:52
上传
评论
收藏 4KB ZIP 举报
wouderw
- 粉丝: 278
- 资源: 2959
最新资源
- html实现儿童节庆祝项目源码
- Typora-1.3.8(含激活文件)
- Python爬取百度贴吧数据.zip
- Python爬取大众点评数据.zip
- 计算机视觉(CV)open CV 人脸识别程序.docx
- python 端午节游戏,选择三个传统的端午节活动之一:包粽子、赛龙舟或挂艾草 根据玩家的选择,游戏会描述相应的情节,并在完成后
- C语言各版块实验题库、实验汇报以及实验教学案例资源
- 数据库连接(MySQL与VS2022)_vs2022 mysql-CSDN博客 (2024_6_1 19_11_34).html
- Flappy bird小游戏
- 数电实验五:555单稳态触发电路、555单稳态触发电路、555构成的施密特触发器
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈