20
7/28/2019 ESD (Lab) - Semester Project Report http://slidepdf.com/reader/full/esd-lab-semester-project-report 1/20  MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY  JA MSHORO, SINDH, PA KISTAN PRACTICAL WORKBOOK EmbeddedSystemsDesign PROJECT NAME: DOOR LOCK SYSTEM SUBMITTED TO:MS. MEHNAZAR SYED DATED: APRIL 23, 2013

ESD (Lab) - Semester Project Report

Embed Size (px)

Citation preview

Page 1: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 1/20

 

MEHRAN UNIVERSITY OF ENGINEERING &

TECHNOLOGY 

JAMSHORO, SINDH, PAKISTAN 

PRACTICAL WORKBOOK

EmbeddedSystemsDesign

PROJECT NAME: DOOR LOCK SYSTEM

SUBMITTED TO:MS. MEHNAZAR SYED

DATED: APRIL 23, 2013

Page 2: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 2/20

Group members:

 Mirbaz Ali Pathan –

10ES55

 Irfan Ali Memon – 10ES44

 Nadia Karim –

10ES57

 RabiaTahir – 10ES65

 Sehar Khan –

10S139

 AdilNizamani – 10ES140

Page 3: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 3/20

Contents:

  Image acquisition

  Image processing

  Principal component analysis (PCA) algorithm 

Page 4: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 4/20

Description: 

Initially, we will make a database with the help of image

processing. The database will contain a specified numberof images of 200 x 180 resolution.

After the initialization, a video stream will be started with

the help of a webcam. During this process, MATLAB will

be monitoring the video stream in order to recognize a

face or multiple faces. If it fails to detect any face, it willcontinue to wait for the input and will not perform any

other operation. However, if it detects a face then it

will immediately capture the respective image, along

with resizing the image to the specified resolution. It will

then pass the captured image to the PCA algorithm,

which reads the image and compares it with the existingdatabase. If the captured image matches with any of the

image stored in database, the required output will be

displayed. But if camera detects more than one face,

MATLAB will switch to its waiting mode.

We have interfaced MATLAB with Arduino. In case if no

face is recognized or if MATLAB is in waiting mode, a

yellow bulb will be turned on with the help of Arduino.

While if a face gets detected, the red bulb will be turned

on.

Page 5: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 5/20

Main script (MATLAB code):

vid = videoinput('winvideo',1,'YUY2_640x480');

set(vid,'ReturnedColorSpace','RGB')% Set the properties of the video object

set(vid, 'FramesPerTrigger', Inf);

vid.FrameGrabInterval = 5;

% a = arduino('COM3');

% a.pinMode(13,'OUTPUT');

%start the video aquisition here

start(vid)

% Set a loop that stop after 100 frames of aquisition

path = uigetdir('D:\Program Files\MATLAB\R2006a\work', 'Select

training database path' );

preview(vid)

while(vid.FramesAcquired<= str2num('Inf'))

% Detecting face with CV toolbox

% Creat vision objectfaceDetector = vision.CascadeObjectDetector;

%capture image from video object

z = getsnapshot(vid);

% detect face in the image

bboxes = step(faceDetector, z);

ifisempty(bboxes)

display('Waiting');

Page 6: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 6/20

% a.digitalWrite(13,0);

else

if size(bboxes) == [1 4]% z = getsnapshot(vid);

im = imcrop(z,bboxes);

resize = imresize(im,[180 200]);

% example(resize,path,a);

example(resize,path);

pause(2);

close all

else

disp('Many Faces');

pause(2);

close all

end

end

end

% Stop the video aquisition.

stop(vid);

% Flush all the image data stored in the memory buffer.

flushdata(vid);

Page 7: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 7/20

Database (MATLAB code):

function T = CreateDatabase(TrainDatabasePath)

% Align a set of face images (the training set T1, T2, ... , TM )

%

% Description: This function reshapes all 2D images of the training

database

% into 1D column vectors. Then, it puts these 1D column vectors in a

row to

% construct 2D matrix 'T'.

%

%

% Argument: TrainDatabasePath - Path of the training database

%

% Returns: T - A 2D matrix, containing all 1D image

vectors.

% Suppose all P images in the training database

% have the same size of MxN. So the length of 1D

% column vectors is MN and 'T' will be a MNxP 2D

matrix.

%

% See also: STRCMP, STRCAT, RESHAPE

Page 8: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 8/20

 

% Original version by Amir HosseinOmidvarnia, October 2007

% Email: [email protected]

%%%%%%%%%%%%%%%%%%%%%%%% File management

TrainFiles = dir(TrainDatabasePath);

Train_Number = 0;

fori = 1:size(TrainFiles,1)

if 

not(strcmp(TrainFiles(i).name,'.')|strcmp(TrainFiles(i).name,'..')|strcmp

(TrainFiles(i).name,'Thumbs.db'))

Train_Number = Train_Number + 1; % Number of all images in thetraining database

end

end

%%%%%%%%%%%%%%%%%%%%%%%% Construction of 2D matrixfrom 1D image vectors

T = [];

fori = 1 : Train_Number

Page 9: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 9/20

Page 10: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 10/20

Eigen face core:

function [m, A, Eigenfaces] = EigenfaceCore(T)

% Use Principle Component Analysis (PCA) to determine the most

% discriminating features between images of faces.

%

% Description: This function gets a 2D matrix, containing all training

image vectors

% and returns 3 outputs which are extracted from training database.

%

% Argument: T - A 2D matrix, containing all 1D image

vectors.

% Suppose all P images in the training database

% have the same size of MxN. So the length of 1D

% column vectors is M*N and 'T' will be a MNxP

2D matrix.

%

% Returns: m - (M*Nx1) Mean of the training database

% Eigenfaces - (M*Nx(P-1)) Eigen vectors of the

covariance matrix of the training database

% A - (M*NxP) Matrix of centered image vectors

%

Page 11: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 11/20

% See also: EIG

% Original version by Amir HosseinOmidvarnia, October 2007

% Email: [email protected]

%%%%%%%%%%%%%%%%%%%%%%%% Calculating the mean image

m = mean(T,2); % Computing the average face image m =

(1/P)*sum(Tj's) (j = 1 : P)

Train_Number = size(T,2);

%%%%%%%%%%%%%%%%%%%%%%%% Calculating the deviation of 

each image from mean image

A = [];

fori = 1 : Train_Number

temp = double(T(:,i)) - m; % Computing the difference image for each

image in the training set Ai = Ti - m

A = [A temp]; % Merging all centered images

end

%%%%%%%%%%%%%%%%%%%%%%%% Snapshot method of 

Eigenfacemethos

Page 12: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 12/20

Page 13: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 13/20

% eigenvectors may be less than (P-1).

L_eig_vec = [];

fori = 1 : size(V,2)

if( D(i,i)>1 )

L_eig_vec = [L_eig_vecV(:,i)];

end

end

%%%%%%%%%%%%%%%%%%%%%%%% Calculating the eigenvectors

of covariance matrix 'C'

% Eigenvectors of covariance matrix C (or so-called "Eigenfaces")

% can be recovered from L's eiegnvectors.

Eigenfaces = A * L_eig_vec; % A: centered image vectors

Page 14: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 14/20

Recognition:

function [OutputName,Recognized_index,Euc_dist_min] =

Recognition(TestImage, m, A, Eigenfaces)

% Recognizing step....

%

% Description: This function compares two faces by projecting the

images into facespace and

% measuring the Euclidean distance between them.

%

% Argument: TestImage - Path of the input test image

%

% m - (M*Nx1) Mean of the training

% database, which is output of 'EigenfaceCore'

function.

%

% Eigenfaces - (M*Nx(P-1)) Eigen vectors of the

% covariance matrix of the training

% database, which is output of 'EigenfaceCore'

function.

%

% A - (M*NxP) Matrix of centered image

Page 15: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 15/20

% vectors, which is output of 'EigenfaceCore'

function.

%

% Returns: OutputName - Name of the recognized image in

the training database.

%

% See also: RESHAPE, STRCAT

% Original version by Amir HosseinOmidvarnia, October 2007

% Email: [email protected]

%%%%%%%%%%%%%%%%%%%%%%%% Projecting centered image

vectors into facespace

% All centered images are projected into facespace by multiplying in

% Eigenface basis's. Projected vector of each face will be its

corresponding

% feature vector.

ProjectedImages = [];

Train_Number = size(Eigenfaces,2);

fori = 1 : Train_Number

Page 16: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 16/20

temp = Eigenfaces'*A(:,i); % Projection of centered images into

facespace

ProjectedImages = [ProjectedImages temp];

end

%%%%%%%%%%%%%%%%%%%%%%%% Extracting the PCA features

from test image

InputImage = TestImage;

temp = InputImage(:,:,1);

[irowicol] = size(temp);

InImage = reshape(temp',irow*icol,1);

Difference = double(InImage)-m; % Centered test image

ProjectedTestImage = Eigenfaces'*Difference; % Test image feature

vector

%%%%%%%%%%%%%%%%%%%%%%%% Calculating Euclidean

distances

% Euclidean distances between the projected test image and the

projection

% of all centered training images are calculated. Test image is

Page 17: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 17/20

% supposed to have minimum distance with its corresponding image in

the

% training database.

Euc_dist = [];

fori = 1 : Train_Number

q = ProjectedImages(:,i);

temp = ( norm( ProjectedTestImage - q ) )^2;

Euc_dist = [Euc_dist temp];

end

[Euc_dist_min ,Recognized_index] = min(Euc_dist);

OutputName = strcat(int2str(Recognized_index),'.jpg');

Page 18: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 18/20

Example:

function example(xc,path)

% You can customize and fix initial directory paths

% TrainDatabasePath = uigetdir('D:\Program

Files\MATLAB\R2006a\work', 'Select training database path' );

TrainDatabasePath = path;

TestImage = xc;

im = TestImage;

T = CreateDatabase(TrainDatabasePath);

[m, A, Eigenfaces] = EigenfaceCore(T);

[OutputName,Recognized_index,Euc_dist_min] =

Recognition(TestImage, m, A, Eigenfaces);

ifRecognized_index == 1 | Recognized_index == 2

disp('10-ES-55');

SelectedImage = strcat(TrainDatabasePath,'\',OutputName);

SelectedImage = imread(SelectedImage);

Page 19: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 19/20

figure,imshow(SelectedImage);

title('Equivalent Image');

% a.digitalWrite(13,1);

Euc_dist_min

pause(5)

close all

else

ifRecognized_index == 3 | Recognized_index == 4

disp('10-ES-55');

SelectedImage = strcat(TrainDatabasePath,'\',OutputName);

SelectedImage = imread(SelectedImage);

figure,imshow(SelectedImage);

title('Equivalent Image');

Euc_dist_min

pause(5)

close all

else

ifRecognized_index == 5 | Recognized_index == 6

disp('11-ES-57');

SelectedImage = strcat(TrainDatabasePath,'\',OutputName);

Page 20: ESD (Lab) - Semester Project Report

7/28/2019 ESD (Lab) - Semester Project Report

http://slidepdf.com/reader/full/esd-lab-semester-project-report 20/20

SelectedImage = imread(SelectedImage);

figure,imshow(SelectedImage);

title('Equivalent Image');

Euc_dist_min

pause(5)

close all

else

disp('unknown')

% a.digitalWrite(13,0);

end

close all

end

end