-
Notifications
You must be signed in to change notification settings - Fork 1
/
Menu.pde
195 lines (171 loc) · 6.18 KB
/
Menu.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
class Manu{
Buttons b1,b2,b3,b4,b5,b6;
Manu(){
b1 = new Buttons("Train",20,height/10);
b2 = new Buttons("Recognize",(width/5)+(width/6),height/10);
b3 = new Buttons("Exaples",3*(width/4),height/10);
//for examples
b4 = new Buttons("Text",50,height/10);
b5 = new Buttons("Images",(width/5)+(width/6),height/10);
b6 = new Buttons("Exit",3*(width/4),height/10);
}
void showButtons(){
b1.drawButton();
b2.drawButton();
b3.drawButton();
}
void showExit(){
b6.drawButton();
}
void showExaples(){
b4.drawButton();
b5.drawButton();
}
int choice(Capture video, PImage prev){
video.loadPixels();
prev.loadPixels();
float worldRecord = 150;
/*
// XY coordinate of closest color
int closestX = 0;
int closestY = 0;
*/
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height/4; y ++ ) {
int loc = x + y*video.width;
// What is current color
color currentColor = video.pixels[loc];
color trackColor = prev.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float bl1 = blue(currentColor);
float r2 = red(trackColor);
float g2 = green(trackColor);
float bl2 = blue(trackColor);
// Using euclidean distance to compare colors
float d = dist(r1, g1, bl1, r2, g2, bl2); // We are using the dist( ) function to compare the current color with the color we are tracking.
// If current color is more similar to tracked color than
// closest color, save current location and current difference
if (d > worldRecord) {
//checking the area of difference
if((b1.bX <= x && b1.bX+100 >= x) && (b1.bY <= y && b1.bY+60 >= y)){
fill(255,0,0);
rect(b1.bX,b1.bY,b1.bW,b1.bH);
return 1;
//So the state is b1.str;
}else if(b2.bX <= x && b2.bX+170 >= x && b2.bY <= y && b2.bY+60 >= y){
fill(0,255,0);
rect(b2.bX,b2.bY,b2.bW,b2.bH);
return 2;
//So the state is b2.str;
}else if(b3.bX <= x && b3.bX+100 >= x && b3.bY <= y && b3.bY+60 >= y){
fill(255,0,255);
rect(b3.bX,b3.bY,b3.bW,b3.bH);
return 3;
//So the state is b3.str;
}
}
}
}
return 0;
}
int choice(Capture video, PImage prev, int f){
video.loadPixels();
prev.loadPixels();
float worldRecord = 150;
/*
// XY coordinate of closest color
int closestX = 0;
int closestY = 0;
*/
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height/4; y ++ ) {
int loc = x + y*video.width;
// What is current color
color currentColor = video.pixels[loc];
color trackColor = prev.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float bl1 = blue(currentColor);
float r2 = red(trackColor);
float g2 = green(trackColor);
float bl2 = blue(trackColor);
// Using euclidean distance to compare colors
float d = dist(r1, g1, bl1, r2, g2, bl2); // We are using the dist( ) function to compare the current color with the color we are tracking.
// If current color is more similar to tracked color than
// closest color, save current location and current difference
if (d > worldRecord) {
//checking the area of difference
if((b4.bX <= x && b4.bX+100 >= x) && (b4.bY <= y && b4.bY+60 >= y)){
fill(255,0,0);
rect(b4.bX,b4.bY,b4.bW,b4.bH);
return 1;
//So the state is b1.str;
}else if(b5.bX <= x && b5.bX+170 >= x && b5.bY <= y && b5.bY+60 >= y){
fill(0,255,0);
rect(b5.bX,b5.bY,b5.bW,b5.bH);
return 2;
//So the state is b2.str;
}else if(b6.bX <= x && b6.bX+100 >= x && b6.bY <= y && b6.bY+60 >= y && f == -1){
fill(255,0,255);
rect(b6.bX,b6.bY,b6.bW,b6.bH);
return 3;
//So the state is b3.str;
}
}
}
}
return 0;
}
int choice(Capture video, PImage prev,Recognize rec){
video.loadPixels();
prev.loadPixels();
float worldRecord = 150;
/*
// XY coordinate of closest color
int closestX = 0;
int closestY = 0;
*/
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height/4; y ++ ) {
int loc = x + y*video.width;
// What is current color
color currentColor = video.pixels[loc];
color trackColor = prev.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float bl1 = blue(currentColor);
float r2 = red(trackColor);
float g2 = green(trackColor);
float bl2 = blue(trackColor);
// Using euclidean distance to compare colors
float d = dist(r1, g1, bl1, r2, g2, bl2); // We are using the dist( ) function to compare the current color with the color we are tracking.
// If current color is more similar to tracked color than
// closest color, save current location and current difference
if (d > worldRecord) {
//checking the area of difference
if((rec.b1x <= x && rec.b1x+rec.b1w >= x) && (rec.b1y <= y && rec.b1y+rec.b1h >= y)){
fill(255,0,0);
rect(rec.b1x,rec.b1y,rec.b1w,rec.b1h);
return 1;
//So the state is b1.str;
}else if((rec.b2x <= x && rec.b2x+rec.b2w >= x) && (rec.b2y <= y && rec.b2y+rec.b2h >= y)){
fill(0,255,0);
rect(rec.b2x,rec.b2y,rec.b2w,rec.b2h);
return 2;
//So the state is b2.str;
}else if(rec.exitX <= x && rec.exitX+100 >= x && rec.exitY <= y && rec.exitY+40 >= y){
fill(255,0,255);
rect(rec.exitX,rec.exitY,100,40);
return 3;
//So the state is b3.str;
}
}
}
}
return 0;
}
}