小笼包喵喵喵 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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配