I'm developing a project faical recongnization based on Eye Distance without image database
1 view (last 30 days)
Show older comments
I'm using two parameter depth of the face using two webcams and eye distance by finding out the centroid of the eyes and class, all these three stored in .mat file and compare with test data. i'm using ecludidean distance i have developed a code which work's but accuracy is very low. Can anyone please help me. i'm trying for 6 months
C = webcamlist;
if length(C)>2
fprintf('All three WebCam is Working' );
else
fprintf('Not All three WebCam is Working' );
end
load('webcamsSceneReconstruction.mat');
vid1 = videoinput('macvideo', 1);
vid2 = videoinput('macvideo', 2);
start([vid1 vid2]);
img1 = getsnapshot(vid1);
img2 = getsnapshot(vid2);
imwrite(img1,'sceneReconstructionLeft.jpg');
imwrite(img2,'sceneReconstructionRight.jpg');
I1 = imread('sceneReconstructionLeft.jpg');
I2 = imread('sceneReconstructionRight.jpg');
I1 = undistortImage(I1,stereoParams.CameraParameters1);
I2 = undistortImage(I2,stereoParams.CameraParameters2);
faceDetector = vision.CascadeObjectDetector;
face1 = step(faceDetector,I1);
face2 = step(faceDetector,I2);
center1 = face1(1:2) + face1(3:4)/2;
center2 = face2(1:2) + face2(3:4)/2;
point3d = triangulate(center1, center2, stereoParams);
distanceInMeters = norm(point3d)/1000;
distanceAsString = round(distanceInMeters,2);
<-----------Training.M-------->
%This Script is used to create DataSet file db.mat
% Euclidean Distance, depth and class are calculated, class is inputted by User and then stored in db.mat
clear all;
close all force;
prompt = 'Enter Name';
N = input(prompt);
setGlobalName(N);
for i=1:5
Depth;
tic;pause(0.01);toc;
DetectFaceandEyes;
calcEyedistance;
StoreEyeDistance;
end
%This Script is used to detect the face by using viola jones Algorithm
%Face is Detected
NotYet = false;
C = webcamlist;
cam=webcam(C{3});
preview(cam);
while ~NotYet
tic;pause(0.10);toc;
I = snapshot(cam);
faceDetect = vision.CascadeObjectDetector();
bbox=step(faceDetect,I);
if ~isempty(bbox)
NotYet = true;
break;
end
end
closepreview;
clear('cam');
face = imcrop(I,bbox);
%Centroid of both eyes is calculated
%RightEye
RighteyeDetect = vision.CascadeObjectDetector('RightEye','MergeThreshold',24);
Righteyebox=step(RighteyeDetect,face);
n=size(Righteyebox,1);
e=[];
for it=1:n
for j=1:n
if (j > it)
if ((abs(Righteyebox(j,2)-Righteyebox(it,2))<68)&& (abs(Righteyebox(j,1)-Righteyebox(it,1))>40))
e(1,:)=Righteyebox(it,:);
e(2,:)=Righteyebox(j,:);
d=1;
break;
end
end
end
if(d == 1)
break;
end
end
Righteyebox(1,:)=e(1,:);
Righteyebox(2,:)=e(2,:);
c=Righteyebox(1,3)/2;
d=Righteyebox(1,4)/2;
%Left Eyes Centroid
eyeCenter1x=Righteyebox(1,1)+c+bbox(1);
eyeCenter1y=Righteyebox(1,2)+d+bbox(2);
e=Righteyebox(2,3)/2;
f=Righteyebox(2,4)/2;
%Right Eyes Centroid
eyeCenter2x=Righteyebox(2,1)+e+bbox(1);
eyeCenter2y=Righteyebox(2,2)+f+bbox(2);
euclideanDistance = CalcDistance(eyeCenter1x,eyeCenter1y,eyeCenter2x,eyeCenter2y);
euclideanDistance = round(euclideanDistance);
%Stroing All three values in db.mat
% Taking value of class from User
prompt = 'Enter Name\n';
N = getGlobalName();
if isempty(N)
Name = input(prompt);
else
Name = N;
end
try
load db;
euclideanDistance = round(euclideanDistance,1);
F=[euclideanDistance Name distanceAsString];
db=[db;F];
save db.mat db
catch
db =[euclideanDistance Name distanceAsString];
save db.mat db
end
% Test Face for Face Reconigastion
clc;
clear all;
close all;
Depth;
tic;pause(0.01);toc;
DetectFaceandEyes;
%%Find Out Which Class it Belong
calcEyedistance;
% Load Dataset
load db.mat
EDtrain =db(:,1);
Ntrain = db(:,2);
Dtrain = db(:,3);
j=0;
% Compare with Database
for (i=1:size(EDtrain,1))
if ((Dtrain(i) == distanceAsString) && (EDtrain(i)==euclideanDistance))
j=i;
break;
elseif ((Dtrain(i) == distanceAsString) || (EDtrain(i)==euclideanDistance))
j=i;
break;
end
end
%Checking For Class
if(j~=0)
det_class=Ntrain(j);
msgbox(strcat('detected class=',num2str(det_class)));
else
msgbox('This is not trained Face');
end
% Train DataSet again if Face not matched
if(j==0)
StoredEyDistance;
end
I'm Getting 3 error most the time , Please tell me How can i remove this error i learned matlab by myself and i'm weak in concept of matlab 1
Index exceeds matrix dimensions.
Error in Depth (line 24)
center2 = face2(1:2) + face2(3:4)/2;
2
Undefined function or variable 'd'.
Error in calcEyedistance (line 26)
if(d == 1)
3
Error in imshow (line 222)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in imcrop>parseInputs (line 252)
imshow(a,cm);
Error in imcrop (line 93)
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] =
parseInputs(varargin{:});
Error in DetectFaceandEyes (line 19)
face = imcrop(I,bbox);
Error in Trianing (line 10)
DetectFaceandEyes;
function euclideanDistance = CalcDistance(x1, y1, x2, y2)
euclideanDistance = sqrt((x2-x1)^2+(y2-y1)^2);
2 Comments
Answers (2)
Image Analyst
on 7 May 2016
Brett Shoelson has a face recognition demo here: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A911
Eye distance/separation doesn't seem like a really robust method. There are hundreds of people that will have the same distance, plus it will vary even on the same person depending on how close that person is to the camera.
We're not really able here to do the kind of consulting to help you build a face recognition app. It looks like it's going to take more than 5 minutes or so.
6 Comments
Image Analyst
on 7 May 2016
Well there you go. You have to check if it's 0 rows and do something, like skip to the next frame because there are no faces in this frame, or something like that.
ahmed nasr
on 27 Dec 2017
did u know the problem with number 1 ?? am stuck with the same error ...
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!