【源码】人脸识别DEMO version 1.1.0.0

部分MATLAB源代码如下:

%% Simple Face Recognition Example

% Copyright 2014-2015 The MathWorks, Inc.

%% Load Image Information from ATT Face Database Directory

faceDatabase = imageSet(‘FaceDatabaseATT’,‘recursive’);

%% Display Montage of First Face

figure;

montage(faceDatabase(1).ImageLocation);

title(‘Images of Single Face’);

%% Display Query Image and Database Side-Side

personToQuery = 1;

galleryImage = read(faceDatabase(personToQuery),1);

figure;

for i=1:size(faceDatabase,2)

imageList(i) = faceDatabase(i).ImageLocation(5);

end

subplot(1,2,1);imshow(galleryImage);

subplot(1,2,2);montage(imageList);

diff = zeros(1,9);

%% Split Database into Training & Test Sets

[training,test] = partition(faceDatabase,[0.8 0.2]);

%% Extract and display Histogram of Oriented Gradient Features for single face

person = 5;

[hogFeature, visualization]= …

extractHOGFeatures(read(training(person),1));

figure;

subplot(2,1,1);imshow(read(training(person),1));title(‘Input Face’);

subplot(2,1,2);plot(visualization);title(‘HoG Feature’);

%% Extract HOG Features for training set

trainingFeatures = zeros(size(training,2)*training(1).Count,4680);

featureCount = 1;

for i=1:size(training,2)

for j = 1:training(i).Count

    trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));

    trainingLabel{featureCount} = training(i).Description;    

    featureCount = featureCount + 1;

end

personIndex{i} = training(i).Description;

end

%% Create 40 class classifier using fitcecoc

faceClassifier = fitcecoc(trainingFeatures,trainingLabel);

%% Test Images from Test Set

person = 1;

queryImage = read(test(person),1);

queryFeatures = extractHOGFeatures(queryImage);

personLabel = predict(faceClassifier,queryFeatures);

% Map back to training set to find identity

booleanIndex = strcmp(personLabel, personIndex);

integerIndex = find(booleanIndex);

subplot(1,2,1);imshow(queryImage);title(‘Query Face’);

subplot(1,2,2);imshow(read(training(integerIndex),1));title(‘Matched Class’);

%% Test First 5 People from Test Set

figure;

figureNum = 1;

for person=1:5

for j = 1:test(person).Count

    queryImage = read(test(person),j);

    queryFeatures = extractHOGFeatures(queryImage);

    personLabel = predict(faceClassifier,queryFeatures);

    % Map back to training set to find identity

    booleanIndex = strcmp(personLabel, personIndex);

    integerIndex = find(booleanIndex);

    subplot(2,2,figureNum);imshow(imresize(queryImage,3));title('Query Face');

    subplot(2,2,figureNum+1);imshow(imresize(read(training(integerIndex),1),3));title('Matched Class');

    figureNum = figureNum+2;

    

end

figure;

figureNum = 1;

end

完整MATLAB源码及PPT课件下载地址:

Face Recognition and Detection.ppt
在这里插入图片描述

更多精彩文章请关注微信号:在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值