Sakura_no_ame
桜花雨
采纳率50%
2019-07-19 12:31

Matlab人脸识别,准确率只有43.5%,找不到错误。在线等,急!!!!!!*★,°*:.☆( ̄▽ ̄)/$:*.°★* 。

已采纳
function Recognize()
%% initialization 
close all; clc;


tic;
%% training
image = zeros(112 * 92, 200);
for i = 1 : 40
    for j = 1 : 5
        buf1 = imread("s" + int2str(i) + "\" + int2str(j) + ".BMP");
        [m, n, ~] = size(buf1);
        buf2 = im2double(reshape(buf1, m * n, 1));
        image(:, 5*(i-1)+j) = buf2;
    end
end

image_mean = zeros(m * n, 200);

for i = 1: 200
    image_mean(:, i) = mean(image, 2);
end

image = image - image_mean;

covariance_matrix = image' * image / 200;
[eigenvector, eigen_value] = eig(covariance_matrix);
for i = 1 : 200
    eigen_value(1, i) = eigen_value(i, i);
end

K = 10;
transformation_matrix = zeros(m * n, K);
for i = 1 : K
    transformation_matrix(:, i) = image * (eigenvector(:, (200 - K + i)) / norm(eigenvector(:, 200 - K + i)) );
end

projection  = transformation_matrix' * image;

%% testing

image_test = zeros(112 * 92, 200);
for i = 1 : 40
    for j = 6 : 10
        buf1 = imread("s" + int2str(i) + "\" + int2str(j) + ".BMP");
        [m, n, ~] = size(buf1);
        buf2 = im2double(reshape(buf1, m * n, 1));
        image_test(:, 5*(i-1)+j-5) = buf2;
    end
end

image_test = image_test - image_mean;

projection_test  = transformation_matrix' * image_test;

pairing_set = zeros(1, 200);
comparing_set = zeros(200, 200);
for i = 1 : 200
    for j = 1 : 200
        c = 0;
        for k = 1 : K
            c = c + abs(projection_test(k, i) - projection(k, j));
        end
        comparing_set(i, j) = c;
    end
    [~, ind] = sort(comparing_set(i, :), 2);
    pairing_set(1, i) = ind(1);
end

n_correct = 0;
corrective_rate = 0;

for i = 1 : 200
    if int16((i - 1) / 5) == int16((pairing_set(i) - 1) / 5)
        n_correct = n_correct + 1;
    end
end
corrective_rate = n_correct / 200;

toc;

end

总时间 1.141460 秒。
准确率43.5%

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • Sakura_no_ame 桜花雨 2年前

    int16是四舍五入的

    点赞 2 评论 复制链接分享