Info

此问题已关闭。 请重新打开它进行编辑或回答。

I am trying to code for face recognition.i get a error as connot use * inner dimesions of matrix should match Pls Help?

2 次查看(过去 30 天)
Pls help me solve the error.The error is coming on the line Eigenfaces = A * L_eig_vec; % A: centered image vectors. or If any one have the working code for face recognition pls mail me.
clear all;
close all;
clc;
vid = videoinput('winvideo', 1, 'RGB24_320x240');
preview(vid);
Image = getsnapshot(vid);
Image = imresize(Image,[200,180]);
testimage=fullfile('C:\Users\owner\Downloads\matlab\test\','1.jpg');
imwrite(Image,testimage);
% %%%%%%%%Paths for TrainDatabase and TestDatabase %%%%%%%%%
TrainDatabasePath ='C:\Users\owner\Downloads\matlab\train';
TestDatabasePath ='C:\Users\owner\Downloads\matlab\test';
%%%%%%%%%%%%%%%recall and compare %%%%%%%%%%%%%%%
TestImage = strcat(TestDatabasePath,'\','1.jpg');
im = imread(TestImage);
%%%%%%%%%%%%%%%Create Database (1) %%%%%%%%%%%%%%%
TrainFiles = dir(TrainDatabasePath);
Train_Number = 0;
for i = 1:size(TrainFiles,1)
if not(strcmp(TrainFiles(i).name,'.')|strcmp(TrainFiles(i).name,'..')|strcmp(TrainFiles(i).name,'Thumbs.db'))
Train_Number = Train_Number + 1; % Nol images in the training database
end
end
T = [];
for i = 1 : Train_Number
str = int2str(i);
str = strcat('\',str,'.jpg');
str = strcat(TrainDatabasePath,str);
img = imread(str);
img = rgb2gray(img);
[irow icol] = size(img);
temp = reshape(img',irow*icol,1);% Reshaping 2D -> 1D image
T = [T temp]; % 'T' grows after each turn
end
if true
%%%%%%%%%%%%%%%Eigenface Core (2) %%%%%%%%%%%%%%%%
m = mean(T,2); % Computing the average face image
Train_Number = size(T,2);
A = [];
for i = 1 : Train_Number
temp = double(T(:,i)) - m;
A = [A temp]; % Merging all centered images
end
L = A'*A; % L is the surrogate of covariance matrix C=A*A'.
[V D] = eig(L);
L_eig_vec = [];
for i = 1 : size(V,2)
if( D(i,i)>1 )
L_eig_vec = [L_eig_vec V(:,i)];
end
end
Eigenfaces = A * L_eig_vec; % A: centered image vectors

回答(1 个)

Walter Roberson
Walter Roberson 2016-4-20
At the point of the error, what is size(A) and size(L_eig_vec) ?
Try
A * L_eig_vec.'

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by