facing problems in doing face recognition using canny edge detection

7 次查看(过去 30 天)
Hi everyone, I am doing my final year project on face recognition using canny edge detection.I have got hold of a code which is quite good but the problem which i am facing is that only two images are matched by it ,that also if the image is same but maybe in different directories or with different extension.The faces are not matching,i.e.,if i use two different images of same person,they are not matching. What i mean to say is that what's happening is image matching not face matching.
I have tried in two ways,one by taking two individual images separately and the other one by taking one input image and searching a folder of images to match with. Now if I input an image of a person and if the same image is present in the folder then its matching or if not present then showing not matching. But,if a different image of that same person is there its not matching.
My code is:
clc;
clear all;
close all;
addpath(genpath('C:\Users\Suchandra\Documents\MATLAB'))
%S=imread('noto.jpg');
[FileName,PathName] = uigetfile({'*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.png','All suported formats'
'*.jpg;*.jpeg','JPEG (*.jpg;*.jpeg)'; ...
'*.gif','Gif (*.gif)'; '*.png','PNG (*.png)'; ...
'*.bmp','Bitmap (*.bmp)'; ...
'*.tif','TIFF (*.tif)'},'Select an image');
S=imread(strcat(PathName,FileName));
[D1,D2,D3]=size(S);
ma=max(D1);
mb=max(D2);
if (ma>=250 || mb>=250);
du=imresize(S,[250 250]);
else
du=S;
end
if (D3>1)
Y=rgb2gray(du);
else
Y=du;
end
figure,imshow(Y);
title(' source image');
H=fspecial('gaussian',1,75);
Gs=imfilter(Y,H);
G=edge(Gs,'canny',0.15);
figure,imshow(G);
title('edge detection of source image');
[X1,Y1]=size(G);
fprintf('X1=%d\t Y1=%d\n',X1,Y1);
E1=0;
E2=0;
E3=0;
E4=0;
E5=0;
E6=0;
E7=0;
E8=0;
for I=10:1:60 %initial value,step,endvalue
for J=15:1:60
fprintf('I=%d\t J=%d\t G(I,J)=%d\n',I,J,G(I,J));
if G(I,J)==1
E1=I;
E2=J;
fprintf('E1=%d\t E2=%d\n',E1,E2);
break;
end
end
end
for I=10:1:60
for J=Y1:-1:60
fprintf('I=%d\t J=%d\t G(I,J)=%d\n',I,J,G(I,J));
if G(I,J)==1
E3=I;
E4=J;
fprintf('E3=%d\t E4=%d\n',E3,E4);
break;
end
end
end
EYE_DIST=((E3-E1)^2+(E4-E2)^2)^0.5
K1=round((E1+E3)/2); %rounds the elements of X to the nearest integers. For complex X, the imaginary and real parts are rounded independently.
K2=round((E2+E4)/2);
fprintf('K1=%d\t K2=%d\n',K1,K2);
for I2=K1:1:250
fprintf('I2=%d\t G(I2,K2)=%d\n',I2,G(I2,K2));
if G(I2,K2)==1
E5=I2;
fprintf('E5=%d\n',E5);
break;
end
end
E6=K2;
fprintf('E6=%d\n',E6);
DIST_NI=((E5-K1)^2+(E6-K2)^2)^0.5
for I4=E5+5:1:X1
fprintf('I4=%d\t G(I4,E6)=%d\n',I4,G(I4,E6));
if G(I4,E6)==1
E7=I4;
fprintf('E7=%d\n',E7);
break
end
end
E8=E6;
fprintf('E8=%d\n',E8);
DIST_NL=((E7-E5)^2+(E8-E6)^2)^0.5
%%%%EXTRACTING FEATURES FROM TARGET IMAGE%%%%
% s=imread('F:\face Interface codeDB\PROJECT code DB\darl\1.jpg');
%=====the data_base search=====
%q = dir(['F:\Somava\All Pictures\Misc1\College and School teachers\','*.jpg']);
directoryname = uigetdir('C:\', ...
['Pick a File directory you',...
'would like to load!']);
fnames=dir(directoryname);
f=filesep;
for k = 1:length(fnames)
[pathstr,name,ext] = fileparts(fnames(k).name);
if strcmpi(ext,'.jpg')==1;
T=imread([directoryname,filesep,...
fnames(k).name]);
[d1,d2,d3]=size(T);
mc=max(d1);
md=max(d2);
if (mc>=250 || md>=250);
dv=imresize(T,[250 250]);
else
dv=T;
end
if (d3>1)
y=rgb2gray(dv); %converts the truecolor image RGB to the grayscale intensity image
else
y=dv;
end
figure,imshow(y);
title(' Target Image' );
h=fspecial('gaussian',1,75); %Create predefined 2-D filter
gs=imfilter(y,h); %N-D filtering of multidimensional images
g=edge(gs,'canny',0.15);
figure,imshow(g);
% imview(g);
title('Edge detection of Target Image' );
[x1,y1]=size(g);
fprintf('x1=%d\t y1=%d\n',x1,y1);
e1=0;
e2=0;
e3=0;
e4=0;
e5=0;
e6=0;
e7=0;
e8=0;
for I=10:1:60
for J=15:1:60
fprintf('I=%d\t J=%d\t g(I,J)=%d\n',I,J,g(I,J));
if g(I,J)==1
e1=I;
e2=J;
fprintf('e1=%d\t e2=%d\n',e1,e2);
break;
end
end
end
for I=10:1:60
for J=Y1:-1:60
fprintf('I=%d\t J=%d\t g(I,J)=%d\n',I,J,g(I,J));
if g(I,J)==1
e3=I;
e4=J;
fprintf('e3=%d\t e4=%d\n',e3,e4);
break;
end
end
end
eye_dist=((e3-e1)^2+(e4-e2)^2)^0.5
k1=round((e1+e3)/2);
k2=round((e2+e4)/2);
fprintf('k1=%d\t k2=%d\n',k1,k2);
for i2=k1:1:x1
fprintf('i2=%d\t g(i2,k2)=%d\n',i2,k2);
if g(i2,k2)==1
e5=i2;
fprintf('e5=%d\n',e5);
break;
end
end
e6=k2;
fprintf('e6=%d\n',e6);
dist_ni=((e5-k1)^2+(e6-k2)^2)^0.5
for i4=e5+5:1:x1
fprintf('i4=%d\t g(i4,e6)=%d\n',i4,e6);
if g(i4,e6)==1
e7=i4;
fprintf('e7=%d\n',e7);
break
end
end
e8=e6;
fprintf('e8=%d\n',e8);
dist_nl=((e7-e5)^2+(e8-e6)^2)^0.5
if (eye_dist==EYE_DIST & dist_ni==DIST_NI & dist_nl==DIST_NL)
display('FACE RECOGNITION: MATCHING')
break
else
display('FACE RECOGNITION: NOT MATCHING')
pause(2)
close all
end
end
end
After canny edge detection of the images the distance calculations based upon which the recognition is taking place,actually i am not sure about it.
So,please can anyone guide me.I am very new to Matlab also. I'll be really grateful. Thank you.

回答(1 个)

saleem peediakal
saleem peediakal 2012-11-20
Hi , Can you please tell why you give the values 10 15 to start the loop? Actually what points are you meant to notify by e5 e6 e7 etc...?

Community Treasure Hunt

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

Start Hunting!

Translated by