-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBrainCamera.pde
More file actions
215 lines (179 loc) · 4.95 KB
/
BrainCamera.pde
File metadata and controls
215 lines (179 loc) · 4.95 KB
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
import processing.video.*;
import gab.opencv.*;
import java.awt.Rectangle;
import com.dhchoi.CountdownTimer;
import com.dhchoi.CountdownTimerService;
//CountdownTimer timer;
//CountdownTimer goal;
//final int idTimer;// = 0;
//int idGoal = 1;
// Timer that has been configured to trigger onTickEvents every 1s and run for 4m
CountdownTimer timer = CountdownTimerService.getNewCountdownTimer(this).configure(1000, 240000);
CountdownTimer goal = CountdownTimerService.getNewCountdownTimer(this).configure(100, 1000);
final int idTimer = timer.getId();
final int idGoal = goal.getId();
String timerCallbackInfo = "[ Tiempo restante: 4:00 ]";
int sEnd=0; //Segundos para el final del ejercicio.
int mEnd=0; //Minutos para el final del ejercicio;
int nivel = 1; //Nivel del juego, 1, 2 o 3
int modo = 0; //Modo de pantalla 0 Bienvenida, 1 Juego, 2 Salida
//int tDesanso = 400; //Miliegundos de descanso entre ejercicios
String palabraActual=""; //Palabra del ejercicio actual
int tipoPalabra=0; //Tipo de ejercicio: 0, Dos manos, 1 Izquierda, 2 Derecha
int ejActual=1; //Numero de ejercicio
//int ejTotal=0; //Numero de ejercicios realizados
int nAciertos=0; //Numero de ejercicios acertados
//int ejFallados=0; //Numero de ejercicios fallados
int minDistancia = 100; //Distancia minima para considerar un acierto
int rCircle = 80; //Radio del círculo de las manos
int rGoal = 200;
PVector objA; //Posicion objetivo A Izquierda
PVector objB; //Posicion objetivo B Derecha
PVector detA; //Posicion detectada A Izquierda
PVector detB; //Posicion detectada B Derecha
color colorA;
color colorB;
//OpenCV section
Capture cam;
OpenCV opencv;
int sWidth = 1280; //Resolucion horizontal
int sHeight = 720; //Resolucion vertical
//boolean drawGame = true;
void setup() {
size(1280, 720);//1280x720
//fullScreen();
objA = new PVector (sWidth/4, sHeight/4);
objB = new PVector (3*(sWidth/4), sHeight/4);
colorA = color(250, 0, 0);
colorB = color(0, 0, 250);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, 1280, 720, 30);// cameras[11]);//11 - 1280 x 720
cam.start();
}
opencv = new OpenCV(this, cam.width, cam.height);
contours = new ArrayList<Contour>();
//imageMode(CENTER);
textSize(38);
textAlign(CENTER, CENTER);
ellipseMode(CENTER);
}
void draw() {
if (cam.available() == true) {
cam.read();
vision();
}
switch(modo)
{
case 0:
drawBienvenida();
break;
case 1:
drawJuego();
break;
case 2:
drawSalida();
break;
}
}
void onTickEvent(CountdownTimer t, long timeLeftUntilFinish) {
if (t.getId() == idTimer) {
sEnd = int(timeLeftUntilFinish / 1000);
mEnd = int (sEnd/60);
timerCallbackInfo = "[ Tiempo restante: " + mEnd+" : "+ sEnd%60+ " ]";
}
if (t.getId() == idGoal) {
rGoal = rGoal - 20;
if (!sobreAcierto()){
rGoal = 200;
goal.reset(CountdownTimer.StopBehavior.STOP_IMMEDIATELY);
}
}
}
void onFinishEvent(CountdownTimer t) {
if (t.getId() == idTimer) {
timerCallbackInfo = "[ Finalizado 0:00 ]";
goSalida();
}
if (t.getId() == idGoal){
rGoal = 200;
acierto();
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
updateAColor();
} else if (keyCode == RIGHT) {
updateBColor();
}
} else if (keyCode == ENTER) {
switch(modo)
{
case 0:
goJuego();
break;
case 1:
goSalida();
break;
case 2:
goBienvenida();
break;
}
} else if (keyCode == ESC) {
timer.stop(CountdownTimer.StopBehavior.STOP_AFTER_INTERVAL);
exit();
}
}
/*
import gohai.glvideo.*;
GLCapture video;
void setup() {
size(320, 240, P2D);
String[] devices = GLCapture.list();
println("Devices:");
printArray(devices);
if (0 < devices.length) {
String[] configs = GLCapture.configs(devices[0]);
println("Configs:");
printArray(configs);
}
// this will use the first recognized camera by default
video = new GLCapture(this);
// you could be more specific also, e.g.
//video = new GLCapture(this, devices[0]);
//video = new GLCapture(this, devices[0], 640, 480, 25);
//video = new GLCapture(this, devices[0], configs[0]);
video.start();
}
void draw() {
background(0);
if (video.available()) {
video.read();
}
image(video, 0, 0, width, height);
}
*/
/*
var capture;
function setup() {
createCanvas(390, 240);
capture = createCapture(VIDEO);
capture.size(320, 240);
//capture.hide();
}
function draw() {
background(255);
image(capture, 0, 0, 320, 240);
filter('INVERT');
}
*/