人脸识别LBP的MATLAB实现
来源:互联网 发布:好用的电磁炉推荐 知乎 编辑:程序博客网 时间:2024/05/29 02:16
人脸识别一般包括人脸检测、识别2大方面,其中有些还需要对人脸进行校正,定位以便达到更准确。本文主要在检测和识别2个方面,做个简单的实时的实现。
%% 导入图像imds = imageDatastore('E:\vs2010_work\test1\test1\data',... 'LabelSource','foldernames',... 'includesubfolder',true,... 'FileExtensions','.jpg');
文件夹名自己命名知道是某个人就好了,即标签。导入的图像形如
%% 检测并保存人脸为png格式faceDetector = vision.CascadeObjectDetector;for i = 1:length(imds.Files) I = readimage(imds,i); bboxes = step(faceDetector, I); maxRect = []; for j = 1:size(bboxes,1) if bboxes(j,3)>=bboxes(1,3) maxRect = bboxes(j,:); end end if ~isempty(maxRect) faceImg = imcrop(I,maxRect); [dstPath,imageName,~] = fileparts(imds.Files{i}); imwrite(faceImg,fullfile(dstPath,[imageName,'.png'])); endend%% 导入检测到的人脸图像pngimdsFace = imageDatastore('E:\vs2010_work\test1\test1\data',... 'LabelSource','foldernames',... 'includesubfolder',true,... 'FileExtensions','.png',... 'ReadFcn',@IMAGERESIZE);[imdsTrain,imdsTest] = splitEachLabel(imdsFace,10);%% 画图看训练的数据集numsCategories = length(categories(imdsTrain.Labels));I = zeros(150,150,3,numsCategories*10);% 图像大小为150*150*3,有numsCategories*10张图像for i = 1:numsCategories*10 I(:,:,:,i) = readimage(imdsTrain,i);endmontage(uint8(I),'size',[numsCategories,10]);%% 提取LBP特征numTrain = length(imdsTrain.Labels);image1 = rgb2gray(readimage(imdsTrain,1));feature1 = extractLBPFeatures(image1, 'Upright',true,'cellsize',[18 18]);featuresMat = zeros(numTrain,length(feature1));for i = 1:numTrain image = rgb2gray(readimage(imdsTrain,i)); featuresMat(i,:) = extractLBPFeatures(image, 'Upright',true,'cellsize',[18 18]);end%% testnumCorrect = 0;numTest = length(imdsTest.Files);for i = 1:numTest grayTest = rgb2gray(readimage(imdsTest,i)); featureTest = extractLBPFeatures(grayTest,'Upright',true,'cellsize',[18 18]); actualLabel = imdsTest.Labels(i); %% predict minDist = realmax; minIndex = 1; for j =1:numTrain currentDist = sum((featureTest-featuresMat(j,:)).^2); if currentDist<minDist minDist = currentDist; predictLabel = imdsTrain.Labels(j);% categorical类型 minIndex = j; end end %% 统计正确的个数 grayActual = rgb2gray(readimage(imdsTrain,minIndex)); figure;imshowpair(grayActual,grayTest,'montage'); if predictLabel == actualLabel numCorrect = numCorrect+1; endenddisp(['正确率:',num2str(numCorrect/numTest)])%% -----------------------------------隔断-----------------%% 识别并显示cam = webcam();% 摄像头接口,没有的话从matlab central网站搜索下载detector = vision.CascadeObjectDetector('lbpcascade_frontalface.xml');detector.MinSize = [110,110];videoPlayer = vision.VideoPlayer;fig = figure;axes('parent',fig)while ishandle(fig) I = snapshot(cam); bboxes = step(detector, I); maxRect = []; for j = 1:size(bboxes,1) if bboxes(j,3)>=bboxes(1,3) maxRect = bboxes(j,:); end end if ~isempty(maxRect)&&(maxRect(1,3)>100) faceImg = imcrop(I,maxRect); grayTest = rgb2gray(faceImg); grayTest = imresize(grayTest,[150,150]); featureTest = extractLBPFeatures(grayTest,'Upright',true,'cellsize',[18 18]); %% predict minDist = realmax; minIndex = 1; for j =1:numTrain currentDist = sum((featureTest-featuresMat(j,:)).^2); if currentDist<minDist minDist = currentDist; predictLabel = imdsTrain.Labels(j);% categorical类型 minIndex = j; end end strLabels = char(predictLabel); RGB = insertObjectAnnotation(I,'rectangle',maxRect,strLabels,'color','g'); step(videoPlayer,RGB); endend
其中用到的IMAGERESIZE函数为:
function output = IMAGERESIZE(input)input = imread(input);output = imresize(input,[150,150]);
阅读全文
1 0
- 人脸识别LBP的MATLAB实现
- LBP及其实现的人脸识别
- LBP人脸识别的python实现
- LBP人脸识别
- LBP人脸识别
- 基于LBP的人脸识别
- 基于LBP的人脸识别技术
- 人脸识别算法-LBP算法及python实现
- LBP(局部二值模式)实现人脸识别
- 人脸识别特征提取(LBP)及其opencv实现
- 训练自己的人脸检测分类器(级联+LBP的Matlab的实现)
- LBP在人脸识别应用方面的综述文章
- 基于LBP和PCA的人脸性别识别方法
- 基于 OpenCV 的 LBP + SVM 人脸识别
- 基于LBP算子的人脸识别算法
- 人脸识别---LBP特征与高维LBP特征
- matlab实现人脸识别
- matlab实现人脸识别
- O
- Android 自定义标题栏 TitleBar
- 如何查看某个端口被谁占用
- 第二章 Zookeeper集群测试(window版)【下】
- Tiled Map Editor(一)
- 人脸识别LBP的MATLAB实现
- 什么是异步
- 菜鸟的red5之旅
- lower_bound和upper_bound的用法
- 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。
- 数组、冒泡排序
- PHP 正则表达式匹配 preg_match 与 preg_match_all 函数
- Rightmost Digit
- Java的21个核心技术点,你知道吗?