-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignRecognition_Kinect_v2_1.m
92 lines (70 loc) · 1.87 KB
/
signRecognition_Kinect_v2_1.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
% PCA v2
% Assign directory \database, pwd identifies current folder
Database = [pwd '\database_v2_1'];
% Check if directory exists
if ~isdir(Database)
errorMessage = sprintf('Error; The following directory does not exist: \n%s', Database);
uiwait(warndlg(errorMessage));
return;
end
% Select files using a specified pattern
filePattern = fullfile(Database, '*.fig');
% Lists out all required files which follows the pattern
reqFiles = dir(filePattern);
if ~exist('S','var')
% get 2-D array database
S = getDatabase_v2_1;
end
%mean image;
m=mean(S,2); %obtains the mean of each row instead of each column
tmimg=double(m);
M=length(reqFiles);
dbx=[];
for i=1:M
temp=double(S(:,i))-tmimg;
dbx=[dbx temp];
end
[eigval, FD]=pca(dbx);
w=FD'*dbx;
%%%%%%%%%%%%%%%%%%
% Kinect input %
fprintf(1, '\nSnapshot in 3 seconds\n');
pause(3);
fprintf(1, '\nIdentifiying unknown sample\n');
if ~exist('depthVid','var')
depthVid = videoinput ('kinect',2);
end
I = getsnapshot(depthVid);
% SEGMENT OUT THE HAND
%make a copy of the original image
I2=I;
% Replace pixel value 0 to 4000. This prevents 0 from being the minimum value
I2((I2<=0))=4000;
% Minus all values in array I2 by the minimum value of itself
I2=I2-min(min(I2));
% Readjust values above 80 to 4000.
I2((I2>90))=4000;
I = I2;
Z = cropImage_v2_1(I);
figure;imshow(Z, [0 100]);
[irow,icol]=size(Z);
% Reshape a 640-by-480 matrix into a matrix that has only 1 column
Z=reshape(Z,irow*icol,1);
S2=double(Z)-tmimg;
wu=FD'*S2;
for i=1:M
diff(i)=sum(abs(wu-w(:,i)));
end
%find(diff==min(diff))
%diff
%Recog [A B C]
finalDiff=[];
for i=1:10:length(reqFiles)
difference = sum(diff(:,i:i+9));
finalDiff = [finalDiff difference];
end
finalDiff
minDiffPos = find(finalDiff==min(finalDiff));
alphabetList = ['A' 'M' 'N' 'S' 'T'];
minDiff = finalDiff(:,minDiffPos);
alphabetSign = alphabetList(:,minDiffPos)