小笼包喵喵喵 2019-07-19 12:31 采纳率: 50%
浏览 573
已采纳

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条回答 默认 最新

  • 小笼包喵喵喵 2019-07-19 14:21
    关注

    int16是四舍五入的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 深度学习运行代码直接中断
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥20 需要完整的共散射点成像代码
  • ¥15 编写vba代码实现数据录入工作
  • ¥15 做过TCL海信电视小米电视相关影视会员软件私我
  • ¥15 Mapreduce是正常的,在运行其他jar包时并没有任何问题,只是在做LogCount.jar 时出的问题。如图所示
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢