-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.pde
433 lines (398 loc) · 13.4 KB
/
Main.pde
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import processing.video.*;
// Variable for capture device
Capture video;
AudioSpeech as;
Movie movie;
// for taking some time
boolean takeTime = false;
// A variable for the color we are searching for.
color trackColor,redFing,greenFing,blueFing,recCol;
ColSets cols;
int i =0,j=0,activation1 = 0,activation2 = 0,chBox;
PImage prev,preBox,swipL;
PImage startImg,recogImg,crrBox,exampleImg1,exampleImg2;
String preExpS = new String("");
String gesM2 = new String("");
// All variable and buildIn datatypes declearations
int ch,globLoc,displayCnt,recogW,recogH;
color traceRed,traceGreen,traceBlue;
boolean red = false,green = false,blue = false,boxPC = false;
float recogX,recogY;
double recPercent;
//Example variables
int examVI = -1,cate = 1;
char exmKey = 'B';
//User define classes declearation
Manu m1;
Recognize rec;
Train t1;
boolean f = false;
void setup() {
size(640,480);
String[] cam = Capture.list();
video = new Capture(this, cam[0]);
video.start();
// Start off tracking for red
trackColor = color(0, 0, 255);
//println(cam[0]);
ch = 10;
prev = createImage(width,height,RGB);
startImg = loadImage("start.png");
t1 = new Train();
red = false;
green = false;
blue = false;
displayCnt=0;
// manu declearation
m1 = new Manu();
// recognition X ,Y,W,H 0,width/4,width/3+50,width/3+50 and images creating
recogX = 0;
recogY = width/4;
recogW = width/3+60;
recogH = width/3+60;
recogImg = createImage(recogW,recogH,RGB);
crrBox = createImage(recogW,recogH,RGB);
preBox = createImage(recogW,recogH,RGB);
rec = new Recognize(40,height/10,180,40,(width/5)+(width/6),height/10,180,40,3*(width/4),height/10);
chBox = 0;
cols = new ColSets();
// text to audio object
as = new AudioSpeech();
// movie = new Movie(this, "exampleVideo.mp4");
// for example images
exampleImg1 = loadImage("examples/A.jpeg");
exampleImg2 = loadImage("examples/upload.png");
swipL = loadImage("examples/back.png");
}
void movieEvent(Movie m) {
m.read();
}
void captureEvent(Capture video) {
if(ch == 0){
//code for state ch -> 1
globLoc = (width/6)+(height/12)*video.width;
traceRed = video.pixels[globLoc];
globLoc = width/2 + (width/12)*video.width;
traceGreen = video.pixels[globLoc];
globLoc = (width/2)+(width/3) + (width/12)*video.width;
traceBlue = video.pixels[globLoc];
}
if(ch == 2){
// recognition
recogImg.copy(video,(int)recogX,(int)recogY,recogW,recogH,0,0,recogImg.width,recogImg.height);
recogImg.loadPixels();
recCol = recogImg.pixels[recogW/2 + recogH/2 * recogImg.width];
if(j < 25){
j++;
}else if(j == 25) {
crrBox.copy(video,(int)recogX,(int)recogY,recogW,recogH,0,0,crrBox.width,crrBox.height);
crrBox.updatePixels();
j = 0;
}
}
// copy prev capture each times
prev.copy(video,0,0,video.width,video.height,0,0,prev.width,prev.height);
prev.updatePixels();
// Read image from the camera
video.read();
}
void draw() {
video.loadPixels();
prev.loadPixels();
if(!takeTime)
image(video,0,0);
//default starting of programe
if(ch == 10){
image(startImg,video.width/3,video.height/3,video.width/3,video.width/3);
}
// gives manus
if(ch == 0){
m1.showButtons();
if(m1.choice(video,prev) == 1){
println("Train button pressed");
ch = 1;
red = false;
blue = false;
green = false;
}
else if(m1.choice(video,prev) == 2){
println("recognize button pressed");
if(red && green && blue)
ch = 2;
else {
textSize(32);
fill(255,10,10);
text("show Colors first in train manu then recognize",50,height/2);
//take some time
displayCnt++;
if(displayCnt == 301)
ch = 10;
}
}else if(m1.choice(video,prev) == 3){
println("result button pressed");
ch = 3;
examVI = -1;
}
}
// ends menu
//color picking state starts
if(ch == 1){
t1.showCol(red,green,blue);
if(red == false && t1.colorPicker(traceRed,(int)t1.rX,(int)t1.rY) != -1){
println("red color picked : "+ t1.colorPicker(traceRed,(int)t1.rX,(int)t1.rY));
redFing = t1.colorPicker(traceRed,(int)t1.rX,(int)t1.rY);
red = true;
}
if(green == false && t1.colorPicker(traceGreen,(int)t1.gX,(int)t1.gY) != -1){
println("green color picked : "+ t1.colorPicker(traceGreen,(int)t1.gX,(int)t1.gY));
greenFing = t1.colorPicker(traceGreen,(int)t1.gX,(int)t1.gY);
green = true;
}
if(blue == false && t1.colorPicker(traceBlue,(int)t1.bX,(int)t1.bY) != -1){
println("blue color picked : "+ t1.colorPicker(traceBlue,(int)t1.bX,(int)t1.bY));
blueFing = t1.colorPicker(traceBlue,(int)t1.bX,(int)t1.bY);
blue = true;
}
// when ever you assign ch = 0 update the previous snapshot
if(red && green && blue){
ch = 11;
displayCnt = 0;
}
}
//Info about color picker
if(ch == 11){
textSize(30);
fill(150, 50, 50);
text("Successfully picked all three colors", video.width/6,video.height/4);
fill(redFing);
rect(video.width/6,video.height/2,50,50);
fill(greenFing);
rect(video.width/2,video.height/2,50,50);
fill(blueFing);
rect((video.width/2)+(video.width/3),video.height/2,50,50);
// for some delay
textSize(30);
fill(150, 50, 50);
text("Please wait Loading Manu....",video.width/6,3 * video.height/4);
displayCnt++;
if(displayCnt == 301){
ch = 0;
displayCnt = 0;
}
}
if(ch == 12){
// for some delay after examples
textSize(30);
fill(150, 50, 50);
text("Please wait Loading Manu....",video.width/6,3 * video.height/4);
displayCnt++;
if(displayCnt == 301){
ch = 0;
displayCnt = 0;
}
}
//track color - recognition part
if(ch == 2){
textSize(32);
fill(255,0,0);
text("show gestures in the below Box",recogX+20,40);
noFill();
stroke(0,0,255);
strokeWeight(2);
rect(recogX,recogY,recogW,recogH);
textSize(22);
fill(0,0,255);
text(chBox +" gesture recognition Mode",recogX+20,recogY-30);
ColSets cols = new ColSets();
//show options for boxes and get the choice
rec.showOpt();
if(m1.choice(video, prev,rec) == 1)
chBox = 2;
else if(m1.choice(video, prev,rec) == 2)
chBox = 1;
else if(m1.choice(video, prev,rec) == 3){
chBox = 0;
ch = 12;
takeTime = false;
}
if(j == 0 && !rec.isDiff(recogImg, crrBox)){
if(chBox == 1){ // if user want to make one window or box gestures
String h = new String("");
h = rec.feedGestures(recogImg,redFing,greenFing,blueFing);
if(h.length() == 0){
activation1 = 0;
takeTime = false;
}
else if(h.length() > 0){
// for recognizing three times then activating
println(activation1);
if(activation1 == 4){
activation1 = 0;
preExpS = "";
String expS = cols.showWord(cols.matchIt(h));
preExpS += expS;
if(expS != "/"){
println(preExpS);
textSize(30);
fill(0,0,255);
text(preExpS,width/2,height/3);
}
takeTime = true;
// shows one gesture is recognize
for(int ii=0;ii<75;ii++){
fill(15,0,255);
rect(0,0,video.width,video.height);
textSize(25);
fill(255,0,0);
text("Gesture recognized!",width/3,height/2);
}
if(preExpS != "/")
as.speakString(preExpS);
}
activation1++;
h = "";
}
activation2 = 0;
}else if(chBox == 2){ // if user want to make two box gestures
String h = new String("");
h = rec.feedGestures(recogImg,redFing,greenFing,blueFing);
if(h.length() == 0){
activation2 = 0;
takeTime = false;
}
else if(h.length() > 0){
// for recognizing three times then activating
println(activation2);
if(activation2 == 3){
activation2 = 0;
preExpS = "";
String expCh = cols.matchIt(h);
if(expCh != "/"){
gesM2 += expCh;
}
takeTime = true;
// shows one gesture is recognize
for(int ii=0;ii<255;ii++){
fill(15,0,255);
rect(0,0,video.width,video.height);
textSize(25);
fill(255,0,0);
text("Gesture recognized!",width/3,height/2);
}
}
if(gesM2.length() == 2){
preExpS = cols.showWord(gesM2);
println(gesM2);
gesM2 = "";
if(preExpS != "/" && preExpS != "//")
as.speakString(preExpS);
}
activation2++;
h = "";
}
activation1 = 0;
}
}
textSize(20);
fill(255,0,0);
if(preExpS != "/")
text(preExpS,2 * width/3-40,height/2+30);
}
//color recognition Ends here
//Exaples starts here
if(ch == 3){
//reading pixels
color examplePic1 = video.pixels[width/5 + (2*height/3+50)*video.width];
color examplePic11 = video.pixels[20 + (height/2)*video.width];
textSize(32);
fill(255,10,10);
text("Choose the examples",50,height/12);
// menu code for examples
m1.showExaples();
color examplePic2;
if(m1.choice(video,prev,2) == 1 || examVI == 1){
examVI = 1;
//image(movie,width/3,20,width/3,width/3);
//movie.play();
// show various categories
examplePic2 = video.pixels[20 + (height/2)*video.width];
if(cate == 1){ // for hospital
textSize(32);
fill(150,10,40);
text("Hospital",50,height/3-30);
textSize(18);
text("I = "+cols.showWord("I"),50,height/3);
text("J = "+cols.showWord("J"),50,height/3+20);
text("K = "+cols.showWord("K"),50,height/3+60);
text("IJ = "+cols.showWord("IJ"),50,height/3+80);
text("IK = "+cols.showWord("IK"),50,height/3+100);
text("JI = "+cols.showWord("JI"),50,height/3+120);
text("JL = "+cols.showWord("JL"),50,height/3+140);
}else if(cate == 2){ // for school
textSize(32);
fill(150,10,40);
text("School",50,height/3-30);
textSize(18);
text("E = "+cols.showWord("E"),50,height/3);
text("F = "+cols.showWord("F"),50,height/3+20);
text("G = "+cols.showWord("G"),50,height/3+40);
text("H = "+cols.showWord("H"),50,height/3+60);
text("EG = "+cols.showWord("EG"),50,height/3+80);
text("FH = "+cols.showWord("FH"),50,height/3+100);
}else if(cate == 3){ // for home
textSize(32);
fill(150,10,40);
text("House",50,height/3-30);
textSize(18);
text("A = "+cols.showWord("A"),50,height/3);
text("B = "+cols.showWord("B"),50,height/3+20);
text("C = "+cols.showWord("C"),50,height/3+40);
text("D = "+cols.showWord("D"),50,height/3+60);
text("AB = "+cols.showWord("AB"),50,height/3+80);
text("AC = "+cols.showWord("AC"),50,height/3+100);
text("AD = "+cols.showWord("AD"),50,height/3+120);
text("BA = "+cols.showWord("BA"),50,height/3+140);
}else if(cate == 4){ // for Goverment
textSize(32);
fill(20,10,100);
text("Goverment place",50,height/3-30);
textSize(18);
text("M = "+cols.showWord("M"),50,height/3);
text("N = "+cols.showWord("N"),50,height/3+20);
text("O = "+cols.showWord("O"),50,height/3+40);
text("MM = "+cols.showWord("MM"),50,height/3+60);
text("MN = "+cols.showWord("MN"),50,height/3+80);
text("MO = "+cols.showWord("MO"),50,height/3+100);
text("NM = "+cols.showWord("NM"),50,height/3+120);
}
image(swipL,10,height/2,20,20);
if(dist(red(examplePic2),blue(examplePic2),green(examplePic2),red(examplePic11),blue(examplePic11),green(examplePic11)) > 30){
cate++;
if(cate == 4)
cate = 1;
}
}
if(m1.choice(video,prev,2) == 2 || examVI == 2){
examVI = 2;
image(exampleImg1,width/10,height/3,200,200);
image(exampleImg2,width/5,2*height/3+20,50,50);
examplePic2 = video.pixels[width/5 + (2*height/3+50)*video.width];
if(dist(red(examplePic2),blue(examplePic2),green(examplePic2),red(examplePic1),blue(examplePic1),green(examplePic1)) > 20){
exampleImg1 = loadImage("examples/"+exmKey+".jpeg");
exmKey++;
if(exmKey == 'P')
exmKey = 'A';
}
}
if(examVI != -1){
m1.showExit();
if(m1.choice(video,prev,-1) == 3){
ch = 12;
displayCnt = 0;
}
}
}
}
void mousePressed(){
ch = 0;
}