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

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

int16是四舍五入的

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

#### 悬赏问题

• ¥20 arcgis制做交通拥堵时变图