资源简介
数字图像处理是计算机科学专业的一门基础学科,而其中人脸识别及分割又是其中最为经典不可缺失的一部分。本文采用MATLAB- VISION包中强大的图像识别功能,对目标图像进行人脸识别。VISION中的级联分类器具有识别人脸,嘴巴,鼻子,左右眼等功能。并且准确度高,能在较为复杂的环境下识别出目标。
代码片段和文件信息
%分类器
clear all
clc
close all
FDetect = vision.CascadeobjectDetector;
%读取照片
image= imread(‘tianyuhang.png‘);
I= rgb2gray(image);%二值化
face_dtect = step(FDetectI);
%%%%%%%%%%%%%%%人脸识别%%%%%%%%%%%%%
figure(1);
imshow(I);hold on
for i = 1:size(face_dtect1)
rectangle(‘Position‘face_dtect(i:)‘LineWidth‘4‘Linestyle‘‘-‘‘EdgeColor‘‘r‘);
end
title(‘Face Detection‘);
hold off;
print(gcf‘-dpng‘‘shibielian.png‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%识别鼻子%%%%%%%%%%%
NoseDetect = vision.CascadeobjectDetector(‘Nose‘‘MergeThreshold‘16);
face_dtect=step(NoseDetectI);
figure(2)
imshow(I); hold on
for i = 1:size(face_dtect1)
rectangle(‘Position‘face_dtect(i:)‘LineWidth‘4‘Linestyle‘‘-‘‘EdgeColor‘‘r‘);
end
hold off;
print(gcf‘-dpng‘‘shibiebizi.png‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%识别嘴%%%%%%%%%%%%%%
mouth_detect = vision.CascadeobjectDetector(‘Mouth‘‘MergeThreshold‘150);
face_dtect=step(mouth_detectI);
figure(3)
imshow(I); hold on
for i = 1:size(face_dtect1)
rectangle(‘Position‘face_dtect(i:)‘LineWidth‘4‘Linestyle‘‘-‘‘EdgeColor‘‘r‘);
end
hold off;
print(gcf‘-dpng‘‘shibiezui.png‘); %保存为png格式的图片到当前路径
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%识别眼%%%%%%%%%%%%
lefteye_detect = vision.CascadeobjectDetector(‘LeftEye‘‘MergeThreshold‘100);
face_dtect=step(lefteye_detectI);
figure(4)
imshow(I); hold on
for i = 1:size(face_dtect1)
rectangle(‘Position‘face_dtect(i:)‘LineWidth‘4‘Linestyle‘‘-‘‘EdgeColor‘‘r‘);
end
hold off;
print(gcf‘-dpng‘‘shibieyan.png‘); %保存为png格式的图片到当前路径
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%识别眼%%%%%%%%%%%%%%%%
% righteye_detect = vision.CascadeobjectDetector(‘RightEye‘‘MergeThreshold‘50);
% face_dtect=step(righteye_detectI);
% figure(5)
% imshow(I); hold on
% for i = 1:size(face_dtect1)
% rectangle(‘Position‘face_dtect(i:)‘LineWidth‘4‘Linestyle‘‘-‘‘EdgeColor‘‘r‘);
% end
% hold off;
% print(gcf‘-dpng‘‘shibieyanright.png‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% *******************************************************************************************************
% ***************************************识别脸部*********************************************************
%%%%%%%%%%%%%%%%%%%提取脸部的红色分量%%%%%%%%%
shibie=imread(‘shibielian.png‘);
hsv=rgb2hsv(shibie);
s=hsv(::2);
bw=im2bw(sgraythresh(s));
se=strel(‘disk‘5);
bw2=imclose(bwse);
bw3=bwareaopen(bw2200);
figure(6);
imshow(bw3);
print(gcf‘-dpng‘‘tiquyan.png‘); %保存为png格式的图片到当前路径
%%%%%%%%%%%%%%%%%填充眼%%%%%%%%%%%%%%%%%
tianchong = imread(‘tiquyan.png‘)
J=tianchong(::1);
K=J>30;%阈值分割,30通过工作空间观察得到
[Lnum] = bwlabel(K8);%连通块标记
F=L>1;%除去周边区域
F(339269)=1;%在工作空间中找到使最大目标不连通的点,赋值,使之连通
BW2 = imfill(F‘holes‘);%填充区域
imwrite(BW2‘tianchongyan.png‘‘png‘)%用imwrite写没有白边
%%%%%%%%%%%
相关资源
- 清扫机器人路径规划算法仿真
- 基于人工神经网络的信号预测在Matl
- 牛顿法matlab程序
- 共轭梯度法相关matlab程序
- 用matlab编写的小动画程序钟摆
- 基于改进遗传算法的路径规划MATLAB实
- RANSAC去除误匹配算法
- MATLAB图像二值化程序源代码
- 伪彩色 MATLAB代码
- (eWiley) Optimum Array Processing最优阵列
- Matlab 图像链码获取
- 任意大小矩阵的zigzag排序Matlab程序
- matlab图像拼接算法
- matlab求解共线方程公式以及生成等高
- 有关emd分解的matlab源程序
- 离散粒子群算法DPSOMatlab代码
- Hata传播模型Matlab代码
- 基于matlab的汉字识别系统和
- matlab批量读入excel表格,可以读文件和
- matlab画ROC曲线
- matlab计算表面曲率
- 禁忌搜索解决背包问题matlab
- 蚁群算法解决背包问题matlab
- matlab遗传算法解决背包问题
- matlab实现meanshift图像分割
- MATLAB常规均匀圆阵波束形成
- 小波基构造函数 Matlab函数
- 多种插值算法Matlab实现--数学建模
- 智能优化算法及其MATLAB源程序
- qpsk调制stbc仿真
评论
共有 条评论