Error using Eigenfaces Too many output arguments. Error in ONL_REC (line 37) testimage=Eigenfaces*E;

1 view (last 30 days)
i want to check or recognized the image using my computer webcam by the following code that had trained in the neural network previously... i mean first i trained the image and save them by outputtttt.mat extension, but i had faced a problem in the line 37 or on the line i stated above
function [ ] =ONL_REC();
load latest
load outputttt
FDetect = vision.CascadeObjectDetector;
vid=videoinput('winvideo',1,'YUY2_320x240');
set(vid,'ReturnedColorSpace','rgb');
preview(vid)
pause (2)
start(vid);
im=getdata(vid,1);
figure(4),imshow(im)
title ('captured image');
closepreview(vid)
is = imresize(im, [256 256]);
imwrite(is,'test.jpg');
closepreview(vid)
I = imread('test.jpg');
BB = step(FDetect,I);
if numel(BB) == 0
error('Nothing was detected, try again');
clc
close all
clear all
else figure,imshow(I);
end
hold on
for i=1
rectangle('Position',BB(i,:),'LineWidth',2,'LineStyle','-','EdgeColor','r');
end
title('Face Detection');
J = imcrop(I,([BB(1) BB(2) BB(3) BB(4)]));
is = imresize(J, [256 256]);
is=rgb2gray(is);
figure(4), imshow (is);
E=reshape(is,65536,1);
E=double(E)-m;
testimage=Eigenfaces'*E;
testimagen=net(testimage);
euc_dist=[];
for i=1:size(outputs,2)
q=outputs(:,i);
temp=(norm(testimagen-q))^2;
euc_dist=[euc_dist temp];
end
euc_distp=[];
for i=1:size(outputs,2)
q=outputs (:,i);
temp=(norm(testimage-q))^2;
euc_distp=[euc_distp temp];
end
[minEcuDist recognizedIndex]=min(euc_dist);
[minEcuDistp recognizedIndexp]=min(euc_distp);
if recognizedIndexp >1.1086e-6
a=imread('ERROR.PNG');
imshow(a);
clc
else
disp('reached');
str1=int2str(recognizedIndexp);
str1=strcat(str1,'.jpg');
im=imread(str1);
figure(5),imshow(im);
title('EQUIVALENT IMAGE ee');
end
if recognizedIndex >1.1086e-6
a=imread('ERROR.PNG');
imshow(a);
clc
else
disp('reached');
str1=int2str(recognizedIndex);
str1=strcat(str1,'.jpg');
im=imread(str1);
figure(6),imshow(im);
title('EQUIVALENT IMAGE nn');
end
hold off
end
%some one please help me with this.....
%but if you need the eigenfaces function, here we go
by the way this code is corretly work. the only problem is in the above ONL_REC function line 37
function [ ] = Eigenfaces( )
z=[];
ta=[];
for ii=1:374
str=int2str(ii);
str=strcat(str,'.JPG');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp];m=mean(z,2);
end
for i=1:size(z,2)
t=double(z(:,i))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R);
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 = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i);
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end
% thank you

Accepted Answer

Walter Roberson
Walter Roberson on 25 May 2019
m is some unknown variable loaded from your latest.mat or outputttt.mat . We have no idea what size it is. You create a variable m inside of Eigenfaces, but that is a variable that is local to that function and is not available outside the function. Except it looks like you save the variables inside latest.mat so I guess that m would have influence -- but remember that you load latest.mat before you run the function Eigenfaces, so you are risking getting an m from an old irrelevant run.
Your function Eigenfaces defines a variable named Eigenfaces and uses it. That becomes confusing to the optimizer about whether the variable or the function is being referred to at any point, risking that the function could end up being called in an infinite loop. Human readers of your code are going to have trouble following it. It is best not to use a variable that is the same name as the function.
Aggh, I just realized that because Eigenfaces is one of the variables created inside function Eigenfaces, you would be loading that variable as part of the .mat and you are expecting the variable from that mat to be used instead of the function by the same name! However, since roughly R2016a-ish, if you load() a .mat that contains a variable that is the same name as a function, and that variable has not been previously defined in the function, then the parser will use the function instead of the variable. You would need to have assigned a value to the variable Eigenfaces before loading latest.mat in order for the variable to be used instead of the function. With the function being used, you would get an error on the line you indicated because your function Eigenfaces does not return any output but the context where you use Eigenfaces requires at least one output value.
This all would not be a problem if your function name and variable name were different.

More Answers (1)

Bereket Ayalew
Bereket Ayalew on 25 May 2019
Edited: Bereket Ayalew on 25 May 2019
yeah there is a confusion between a variable and function name that was eigenfaces...... thank you very much!!! but after this change the error that was before is fixed and a new error occured in line 48.....
says
Error using -
Matrix dimensions must agree.
Error in ONL_REC (line 48)
temp=(norm(testimage-q))^2;
do you have solution for this please??

Tags

Community Treasure Hunt

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

Start Hunting!