there is an minor error in my code @ 75 th line please help me.

1 view (last 30 days)
% code to open the webcam of laptop and to capture image
Clear all
Close all
clc
button=input('would you like to open the camera?(y \ n)!','s');
if strcmp(button,'y')
disp(button)
vid=videoinput('winvideo',1,'YUY2_320x240');
% code to convert image to RGB format
set(vid,'ReturnedColorSpace','rgb');
preview(vid)
start(vid);
im=getdata(vid,1);
figure,imshow(im)
imwrite(im,'C:\Users\Dell Vostro\Desktop\TrainDatabase\1.jpg');
% number of images on your training set.
M=3;
%Chosen std and mean.
um=100; ustd=80;
%read and show images (jpg);
S=[];
figure(1);
for i=1:M
str=strcat('C:\Users\Dell Vostro\Desktop\TestDatabase\',int2str(i),'.jpg');
eval('img=imread(str);');
subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
imshow(img)
if i==3
title('Training set','fontsize',18)
end
drawnow;
[irow icol]=size(img);
img(irow,icol) ;
temp=reshape(img,irow*icol,1);
S=[S temp];
end
%Here we change the mean and std of all images. We normalize all images.
for i=1:size(S,2)
temp=double(S(:,i));
m=mean(temp);
st=std(temp);
S(:,i)=(temp-m)*ustd/st+um;
end
%show normalized images
figure(2);
for i=1:M
str=strcat('C:\Users\kandla\Desktop\Project\photo\',int2str(i) ,'.jpg');
img=reshape(S(:,i),icol,irow);
img=img';
eval('imwrite(img,str)');
subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
imshow(img)
drawnow;
if i==3
title('Normalized Training Set','fontsize',18)
end
end
%mean image;
m=mean(S,2);
%obtains the mean of each row instead of each column
tmimg=uint8(m);
img=reshape(tmimg,icol,irow);
img=img';
figure(3);
imshow(img);
title('Mean Image','fontsize',18)
% Change image for manipulation
dbx=[];
for i=1:M
temp=double(S(:,i));
dbx=[dbx temp];
end
%Covariance matrix
C =cov(A'.A)
L=AA'
A=dbx';
L=A*A';
% vv are the eigenvector for L
% dd are the eigenvalue for both L=dbx'*dbx and C=dbx*dbx';
[vv dd]=eig(L);
% Sort and eliminate those whose eigenvalue is zero
v=[];
d=[];
for i=1:size(vv,2)
if(dd(i,i)>1e-4)
v=[v vv(:,i)];
d=[d dd(i,i)];
end
end
%sort, will return an ascending sequence
[B index]=sort(d);
ind=zeros(size(index));
dtemp=zeros(size(index));
vtemp=zeros(size(v));
len=length(index);
for i=1:len
dtemp(i)=B(len+1-i);
ind(i)=len+1-index(i);
vtemp(:,ind(i))=v(:,i);
end
d=dtemp;
v=vtemp;
%Normalization of eigenvectors
for i=1:size(v,2)
kk=v(:,i);
temp=sqrt(sum(kk.^2));
v(:,i)=v(:,i)./temp;
end
%Eigenvectors of C matrix
u=[];
for i=1:size(v,2)
temp=sqrt(d(i));
u=[u (dbx*v(:,i))./temp];
end
%Normalization of eigenvectors
for i=1:size(u,2)
kk=u(:,i);
temp=sqrt(sum(kk.^2));
u(:,i)=u(:,i)./temp;
end
% show eigenfaces;
figure(4);
for i=1:size(u,2)
img=reshape(u(:,i),icol,irow);
img=img';
img=histeq(img,255);
subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
imshow(img)
drawnow;
if i==3
title('Eigenfaces','fontsize',18)
end
end
% Find the weight of each face in the training set.
omega = [];
for h=1:size(dbx,2)
WW=[];
for i=1:size(u,2)
t = u(:,i)';
WeightOfImage = dot(t,dbx(:,h)');
WW = [WW; WeightOfImage];
end
omega = [omega WW];
end
% Note: the input image must have a bmp or jpg extension.
% code to read input image that have been captured by the %
% webcam as discussed above
InputImage= imread(strcat('C:\Users\kandla\Desktop\Project\photo\1.jpg') );
figure(5)
subplot(1,2,1)
imshow(InputImage);
colormap('gray');
title('Input image','fontsize',18)
InImage=reshape(double(InputImage)',irow*icol,1);
temp=InImage;
me=mean(temp);
st=std(temp);
temp=(temp-me)*ustd/st+um;
NormImage = temp;
Difference = temp-m;
NormImage = Difference;
p = [];
aa=size(u,2);
for i = 1:aa
pare = dot(NormImage,u(:,i));
p = [p; pare];
end
ReshapedImage = m + u(:,1:aa)*p;
%m is the mean image, u is the eigenvector
ReshapedImage = reshape(ReshapedImage,icol,irow);
ReshapedImage = ReshapedImage';
%show the reconstructed image. ???????
subplot(1,2,2)
imagesc(ReshapedImage);
colormap('gray');
title('Reconstructed image','fontsize',18)
InImWeight = [];
for i=1:size(u,2)
t = u(:,i)';
WeightOfInputImage = dot(t,Difference');
InImWeight = [InImWeight;
WeightOfInputImage];
end
ll = 1:M;
figure(6);
subplot(1,2,1)
stem(ll,InImWeight)
title('Weight of Input Face','fontsize',14)
% Find Euclidean distance ??Euclidean??
e=[];
for i=1:size(omega,2)
q = omega(:,i);
DiffWeight = InImWeight-q;
mag = norm(DiffWeight);
e = [e mag];
end
kk = 1:size(e,2);
subplot(1,2,2)
stem(kk,e)
title('Eucledian distance of input image','fontsize',14)
MaximumValue=max(e);
MinimumValue=min(e);
avg=mean(e);
display(['average=',num2str(avg)]);
if (avg<80000)
display(' u succeeded');
else
display(' face authentication failed');
end
else if strcmp(button,'n')
disp(button)
disp('gudbye')
end
  1 Comment
James Tursa
James Tursa on 29 Apr 2015
Which line is the 75th line? Please post the error message you are getting (copy & paste the entire message).

Sign in to comment.

Answers (1)

Jan
Jan on 30 Apr 2015
The code should fail in the 1st line already:
Clear all
Matlab is case-sensitive and should not recognize the clear command with an uppercase C. The same appears in the 2nd line.
And if you omit the evil clear all, you can even use the debugger: Set a breakpoint in the line 75 and inspect the values of the locally used variables.

Tags

Community Treasure Hunt

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

Start Hunting!