-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gesture.m
142 lines (94 loc) · 3.77 KB
/
Gesture.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
133
134
135
136
137
138
139
140
141
142
im=imread('4.1.jpg'); % Reading the image
figure(1);
imshow(im);
title('Orginal Image');
se = strel('ball',5,5); % creates a structuring element, SE, of the type specified by shape
img = imdilate(im,se); % dilates the image
figure(2);
imshow(img);
title('Dilated image to make Surface smooth');
im1=rgb2gray(img); %rgb to gray conversion
figure(3);
imshow(im1);
title('RGB image To greylevel image');
th=graythresh(im1); %computes a global threshold that can be used to convert intensity image to binary image
im2=im2bw(im1,th); %Convert image to binary image, based on threshold value
figure(4);
imshow(im2);
title('GreyLevel to Binary');
im3=imcomplement(im2); %complements the image
figure(5);
imshow(im3);
title('Compliment of binary');
im3=imfill(im3,'holes'); %fills holes in the image
figure(6);
imshow(im3);
title('Image with holes removed');
im4=bwareaopen(im3,10000); %removes all binary components less than 10000 pixels
figure(7);
imshow(im4);
title('Removes objects less than 10000 pixels ');
figure(8);
imshow(im4);
title('Centroid is found');
s1 = regionprops(im4,'Centroid'); %returns measurements for the 'Centroid' for each labeled region in the label matrix L.
centroids = cat(1, s1.Centroid); %To concatenate s1.Centroid into a matrix, specify dimension dim as 1.
hold(imgca,'on') %displaying the image and superimposing the centroids
plot(centroids(1),centroids(2),'r*')
hold(imgca,'off')
im5=bwmorph(im4,'thin',inf); %thinning the image im4
figure(9);
imshow(im5);
title('Image is made infinitly thin');
[r,c]=size(im5);
for i=1:r %removing the portion on the left side of centroid
for j=1:c
if j<centroids(1)
im5(i,j)= 0;
end
end
end
figure(10);
imshow(im5);
title('Portion left to the centroid is cutoff');
%calculate end points
cnt=0;
pt=0;
[g h]=size(im5);
for i=1:g
for j=1:h
if(im5(i,j)==1)
cnt=0;
m=i;
n=j;
m=m-2;
n=n-2;
for x=1:3
for y=1:3
%disp(y)
if(im5(m+x,n+y)==1)
cnt=cnt+1;
end
end
end
if(cnt==2) %checking whether its an end point
pt=pt+1;
end
end
end
end
disp('Number of fingers=');
a=pt/2;
disp(a)
if (a==1)
disp('Move Forward')
end
if (a==2)
disp('Move Backward')
end
if (a==3)
disp('Move Left')
end
if (a==4)
disp('Move Right')
end