'Face detection and recognition' I want to display test image and recognised image and if match not found i want display match not found message

1 view (last 30 days)
DBPath='D:\Matlab_prblms\face_database';
D=dir(DBPath)
[mFiles t]=size(D)
mSamples= mFiles-2;
A=zeros(size(image,1),mSamples);
size(A)
for i= 3 : mFiles
D(i).name
image=imread(strcat(DBPath,'\',D(i).name));
[x, y, z]= size(image)
if(z==3)
image=rgb2gray(image);
end
image=imresize(image,[64,64]);
image = image(:);
A(:,i-2)=double(image);
end
%At=A.';s
M=mean(A');
phi=(A-M');
C=phi'*phi;
k=10;
[V D]= eigs(C,k);
size(phi)
size(V)
U=phi*V;
size(U)
for i=1 :k
length=norm(U(:,i));
U(:,i)=U(:,i)./length;
end
wi=zeros(k,mSamples);
for i=1 : mSamples
wi(:,i)= U'*A(:,i);
end
testImage = cap_img();
[
% testImage=imread('D:\Matlab_prblms\face_database\17.tif');
testImage = rgb2gray(testImage);
testImage=imresize(testImage,[64 ,64]);
testImage=testImage(:);
t=U'*double(testImage);
mindist=999999;
index=-1;
for i=1 : mSamples
distVal = (wi(:,i) - t).*(wi(:,i) - t);
if(mindist > distVal)
mindist = distVal;
index=i;
end
end
for i = 1 : mSamples
q = t(:,i);
temp = ( norm( t - q ) )^2;
mindist= [mindist temp];
end
index
  5 Comments
Santhosh Nayak
Santhosh Nayak on 28 Jul 2017
yes Im using eigenvectors mindist so in that case how can display message if matching image in folder not found
Carl
Carl on 28 Jul 2017
Are you asking how to display the message, or how to identify when there is no match? For displaying a message, you can use something simple like the "disp" function. For identifying if there is no match, that would depend on how you interpret that mindist value.
Either way, I would strongly suggest that you follow the link posted by Image Analyst below. As they mentioned, it contains a much more robust approach to your original problem.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 26 Jul 2017
I doubt any robust face recognition code is going to be only like 100 lines of code. You may want to look at how Brett, of The Mathworks, did it here: http://www.mathworks.com/matlabcentral/fileexchange/49914-streaming-face-detection--training--recognition
  2 Comments
Santhosh Nayak
Santhosh Nayak on 29 Jul 2017
Edited: Image Analyst on 29 Jul 2017
In that link they are making use of surf and fast but I'm using PCA eigenvector, and they have created montages. If tried to implement that, I have to re-code everything is there any easy method to find min distance and compare suggest if any.
I tried ismember but that isn't working. Is there any other way that I can use?
Thank you
Image Analyst
Image Analyst on 29 Jul 2017
It seems you're committed to getting your method working and don't want to make major changes to your existing code.
To find minimum distances I always use the Pythagorean theorem, sqrt(), to get distances and then use min() to find the min of the distances, OR use pdist2() to find distances of every point to every other point and then use min(). Whether one of those two methods will help you, I don't know. That's about all I can say.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!