App A
App A
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% delete(instrfindall);
% serialPorts = instrhwinfo ('serial') ;
% nPorts = length(serialPorts.SerialPorts);
% set(handles.SerialCOM, 'String','Com 3');
% set(handles.SerialCOM,'Value',3);
% --- Outputs from this function are returned to the command line.
function varargout = RealTimeFaceDoorLock_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
T = CreateDatabase(strcat(datapath,'\'));
[m, A, Eigenfaces] = EigenfaceCore(T);
if numPts < 10
% Detection mode.
bbox = faceDetector.step(videoFrameGray);
if ~isempty(bbox)
% Find corner points inside the detected region.
points = detectMinEigenFeatures(videoFrameGray, 'ROI', bbox(1, :));
else
% Tracking mode.
[xyPoints, isFound] = step(pointTracker, videoFrameGray);
visiblePoints = xyPoints(isFound, :);
oldInliers = oldPoints(isFound, :);
if numPts >= 10
% Estimate the geometric transformation between the old points
% and the new points.
[xform, oldInliers, visiblePoints] = estimateGeometricTransform(...
oldInliers, visiblePoints, 'similarity', 'MaxDistance', 4);
end
% Display the annotated video frame using the video player object.
imshow(D_Image)
if Flag_v
KeepCameraRunning = false;
break;
end
else
KeepCameraRunning = false;
release(pointTracker);
release(faceDetector);
break;
end
end
KeepCameraRunning = false;
KeepCameraRunning = false;
Flag_v = true;
% Detection mode
%% Annotate detected faces.
IFace = insertObjectAnnotation(framergb, 'rectangle', bbox, 'Detected Face');
imshow(IFace);
KeepCameraRunning = false;
Flag_v = true;
if Flag_v && (KeepCameraRunning == false)
%% Crop detected faces.
CropFace = imcrop(IFace, bbox);
imshow(CropFace); title('Cropped Face');
end
global m A Eigenfaces;
global framergb KeepCameraRunning serConn;
KeepCameraRunning = false;
delete(instrfindall);
set(handles.SerialCOM, 'String','Com 4');
serConn = serial('com4', 'TimeOut', 1,'BaudRate',300);
format compact
fopen(serConn);
%% Detect faces.
bboxes = step(faceDetector, framergb);
Face = imcrop(framergb,bboxes);
CF = imresize(Face, [200,200]);
imshow(CF),
TestImage = CF;
% threshould = 0.09;
threshould=str2double(get(handles.Th_EText,'String'));
%%%%%%%%%%%%%%%%%%
ProjectedImages = [];
Train_Number = size(Eigenfaces,2);
for i = 1 : Train_Number
temp = Eigenfaces'*A(:,i); % Projection of centered images into facespace
ProjectedImages = [ProjectedImages temp];
end
69
Euc_dist = [];
for i = 1 : Train_Number
q = ProjectedImages(:,i);
temp = ( norm( ProjectedTestImage - q ) )^2;
Euc_dist = [Euc_dist temp];
end
Euc_dist = Euc_dist/maximum;
else
index=Recognized_index;
set(handles.Recog_EText,'String','Known Person: Unlock the Door!')
fprintf(serConn, 1);
fclose(serConn);
end
display(Euc_dist_min)
display(index)
display(Recognized_index);
KeepCameraRunning = false;
Flag_v = false;
delete(serConn);
clear('vidcam')
clear all