小笼包喵喵喵 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是四舍五入的

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器