尝试执行人脸识别算法总是会给出错误的答案

时间:2019-04-03 15:05:27

标签: octave face-recognition face

我一直在尝试做一个人脸识别算法,以尝试使其显示出某物是否为人脸,某物是否为人脸,是否为已知人脸以及该已知人脸是或如果不是人脸,我会尝试使用图像矩阵形成的矩阵的特征值作为矢量显示为第一行,然后显示第二行,依此类推,对每一行取均值,然后从矩阵中减去数据库,然后构造一个矩阵以找到其特征值,然后构造一些投影图像。

我尝试使用2个函数来做到这一点:eigenface_core建立所有数据库,而人脸识别则计算距离。

第一个功能:

function [m A eigenfaces pr_img] = eigenface_core(database_path)
  files = dir(fullfile(database_path, '*.jpg'));
  T = [];
  m = [];
  for i = 1 : numel(files)
    image_matrix = double(rgb2gray(imread(fullfile(database_path, files(i).name))));
    image_matrix = image_matrix';

    SIZE = size(image_matrix);
    v = image_matrix(:);
    T(:, i) = v;
  endfor
  for i = 1 : size(T)
    m(i) = mean(T(i, :));
  endfor
  m = m';
  A = T - m;
  [V S] = eig(A'*A);
  lambda = diag(S);
  %[lambda, order] = sort(lambda, 'descend');
  %V = V(:, order);
  for i = 1 : size(lambda)
    if(lambda(i) < 1)
      V(:, i) = [];
    endif
  endfor
  eigenfaces = A*V;
  pr_img = eigenfaces'*A;
end

第二个功能:

function [min_dist output_img_index] = face_recognition(image_path, m, A, eigenfaces, pr_img)
  image_matrix = double(rgb2gray(imread(image_path)));
  T = [];
  image_matrix = image_matrix';
  T = image_matrix(:);
  miu = mean(T);
  B = T - miu;
  %SIZE = size(image_matrix);
  %figure, imshow(reshape(B, SIZE));
  prtest_img = eigenfaces'*B;
  %disp(prtest_img);
  %imshow(prtest_img);
  min_dist = 9999999999999;
  for i = 1 : size(pr_img, 2)
    if (norm(pr_img(:, i) - prtest_img) < min_dist)
       min_dist = norm(pr_img(:, i) - prtest_img);
       output_img_index = i;
    endif
  endfor
end

0 个答案:

没有答案