-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainMenu.m
132 lines (122 loc) · 5.13 KB
/
MainMenu.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
% clear all;
% close all;
% clc;
while (1==1)
choice=menu('Face Recognition',...
'Generate Database',...
'Train system',...
'Feature Extraction',...
'Generate Classifier',...
'Test',...
'Open Image From System',...
'Exit');
%% Generating Database " loading dataset into matlab"
if (choice ==1)
choice2 = questdlg('Generate a new database?', ...
'Warning...',...
'Yes', ...
'No','No');
switch choice2
case 'Yes'
pause(0.1);
facedatabase = imageSet('data','recursive');
case 'No'
end
end
%%Establishing Training set and test set by dividing the dataset in 8:2
if (choice == 2)
if (~exist('facedatabase','var'))
warndlg('Please generate database first!\n');
else
[training,test] = partition(facedatabase,[0.8 0.2]);
end
end
%%Feature Extraction
if (choice == 3)
if (~exist('facedatabase','var'))
warndlg('Please generate database first!');
%fprintf('Please generate database first!\n');
elseif(~exist('test','var') || ~exist('training','var'))
warndlg('Training the system first!\n');
else
trainingFeatures = zeros(size(training,2)*training(1).Count,4680);
featureCount = 1;
for i=1:size(training,2)
for j= 1:training(i).Count
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),1));
trainingLabel{featureCount} = training(i).Description ;
featureCount = featureCount +1;
end
personIndex{i}= training(i).Description;
end
end
end
%%Generating Classfier using ecoc machine learning algorithm
if (choice == 4)
if (~exist('facedatabase','var'))
warndlg('Please generate database first!');
elseif(~exist('test','var') || ~exist('training','var'))
warndlg('Training the system first!\n');
elseif(~exist('trainingFeatures','var'))
warndlg('Extract Features before proceding to classifer!');
else
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
end
end
%% Prediction "Recognition"
if (choice == 5)
if (~exist('facedatabase','var'))
warndlg('Please generate database first!');
elseif(~exist('test','var') || ~exist('training','var'))
warndlg('Training the system first!\n');
elseif(~exist('trainingFeatures','var'))
warndlg('Extract Features before proceding to classifer!');
elseif(~exist('faceClassifier','var'));
warndlg('Run Classifier First');
else
figure;
figureNum =1;
for person = 1:5
for j =1:2
queryImage = read(test(person),j);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
booleanIndex = strcmp(personLabel,personIndex);
integerIndex = find(booleanIndex);
subplot(5,4,figureNum);imshow(imresize(queryImage,3));title('QueryImage');
subplot(5,4,figureNum+1);imshow(read(training(integerIndex),1)); title('Match');
figureNum = figureNum+2;
end
end
end
end
%% Reading image from a path and recognising the person from the dataset
if (choice == 6)
if (~exist('facedatabase','var'))
warndlg('Please generate database first!');
elseif(~exist('test','var') || ~exist('training','var'))
warndlg('Training the system first!\n');
elseif(~exist('trainingFeatures','var'))
warndlg('Extract Features before proceding to classifer!');
elseif(~exist('faceClassifier','var'));
warndlg('Run Classifier First');
else
pause(0.1);
[file_name file_path] = uigetfile ({'*.pgm';'*.jpg';'*.png'});
if file_path ~= 0
filename = [file_path,file_name];
queryImage = imread(filename);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
booleanIndex = strcmp(personLabel,personIndex);
integerIndex = find(booleanIndex);
subplot(1,2,1);imshow(queryImage);title('Query Image');
subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched');
end
end
end
if (choice == 7)
clear choice choice2
return;
end
end