Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/multi/SRC/clicksCVXO.cpp
blob: 5a2386c72bc0a6b7d17a0afc6f6aa3df92e6e05e (plain)
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/*
 * clicksCV.cpp
 *
 *  Created on: 28/06/2010
 *      Author: smarichal
 */

#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifndef __APPLE__
#include <GL/gl.h>
#include <GL/glut.h>
#else
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif
#include <AR/gsub.h>
#include <AR/video.h>
#include <AR/param.h>
#include <AR/ar.h>
#include <AR/arMulti.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include "Utilidades.h"
#include "cvUtilities.h"
#include "UtilidadesSDL.h"
#include "stdio.h"
#include "stdlib.h"
#include <unistd.h>
#include <math.h>
#include <formatopixel.h>

#include "cvUtilities.h"

			/*************************************************************************************************************************
			 * 									CONFIGURACIONES GENERALES DE LA APLICACION
			 *************************************************************************************************************************/
int mostrarVideo = 0;
int dibujarCubos = 0;

int mostrarRadar = 1;

			/*************************************************************************************************************************
			 * 									CONFIGURACION DE RECONOCIMIENTO DE COLORES
			 *************************************************************************************************************************/
#define MIN_AREA 600
#define MAX_AREA 1500

int min_area = MIN_AREA;
int max_area = MAX_AREA;
#define MIN_H 0
#define MAX_H 0
#define MIN_S 0
#define MAX_S 0
#define MIN_B 0
#define MAX_B 0
#define CANT_HISTORIA 4
#define UMBRAL 5
#define UMBRAL_AREA_APUNTADOR 20  //El area del apuntador y el area del marcador tienen una relacion definida mediante calibracion. Usamos un
									//umbral de error al que declaramos como UMBRAL_AREA_APUNTADOR. Es decir si la zona de estudio donde buscamos el
								//apuntador mide 300 y la relacion es de 1/2 (el apuntador mide la mitad del marcador) entonces buscaremos apuntadores entre
								//las cotas (150 - UMBRAL_AREA_APUNTADOR)  y (150 - UMBRAL_AREA_APUNTADOR)
#define ERODE  2
#define DILATE  1
#define SMOOTH  0
#define OFFSET_ROI 5			//Cuanto mas grande mas grande sera el ROI donde busco el apuntador
#define MIN_AREA_WIDTH_HEIGHT 5	//Este valor sirve para indicar cual es el area minima en la cual se busca un apuntador.
								//Por ejemplo si el marcador se encuentra apenas dentro de la pantalla y el height o el width no superan este valor entonces
								//el area no sera analizada en busca de un apuntador

int umbral = UMBRAL;
int  minH = MIN_H, maxH = MAX_H, minS = MIN_S, maxS = MAX_S, minB = MIN_B,maxB = MAX_B;
int num_apuntadores =0;

int debugImg = 0;		//Parametro para hayObjetoColor. Si se le pasa 1 y se le pasa una ventana entonces va reproduciendo el ROI. Sino crea una ventana nueva pero detiene la aplicacion hasta tocar una tecla
			/********************************************************************************************************************************
			 * 								CONFIGURACION DE ARTOOLKIT Y MARCADORES
			 ********************************************************************************************************************************/

#define MAX_MARCADORES 30
/* set up the video format globals */

#ifdef _WIN32
char			*vconf = "Data\\WDM_camera_flipV.xml";
#else
char			*vconf = "";
#endif

int             xsize, ysize;
int             thresh = 100;
int             count = 0;

char           *cparam_name    = "Data/camera_para.dat";
ARParam         cparam;

char                *config_name = "Data/prototipo1/prototipo1.dat";
ARMultiMarkerInfoT  *config;


IplImage* img =NULL;
uchar* data1 =NULL;
IplImage* mono_Image = NULL;

/*La posicion i del arreglo corresponde al marcador con con patt_id=i*/
ARCoordMarcador marcadoresOcultos[MAX_MARCADORES]; //MAX_MARCADORES es la maxima cantidad -1 de marcadores que la aplicacion puede manejar.



/**************************************************************************************************************************************
 * ************************************************************************************************************************************
 *  										VARIABLES DEL PROTOTIPO
 * ************************************************************************************************************************************
 * ************************************************************************************************************************************/

/* Representacion de los elementos*/
Elemento elementos[MAX_MARCADORES];	//El indice el elemento coincide con el id del elemento que tambien coincide con el id del marcador artoolkit
int cantElementosCargados = 0;

int elementoConjuntoA = -1; //indice del elemento del conjunto A seleccionado
int elementoConjuntoB = -1; //indice del elemento del conjunto B seleccionado
int correspondenciaCorrecta = 0; //indica si el elemento del conjunto A y el del conjunto B
								 // que se seleccionaron se corresponden
int correspondenciaIncorrecta = 0;

int xNombreRelacion = 400;
int yNombreRelacion = 20;

int xConjuntoA = 20;
int xConjuntoB = 550;

int yConjuntoA = 150;
int yConjuntoB = 150;

int anchoPantalla = 900;
int altoPantalla = 800;

//Son los id de las imagenes actualmente desplegadas en la pantalla
int idSDLImagenPantallaA = -1;
int idSDLImagenPantallaB = -1;

//Sonidos del click y de error
char clickSound[255];
char errorSound[255];

//Variable para mantener el historico de los ultimos marcadores seleccionados
//Lo usamos como buffer circular
Historico historico;

#define CONJUNTO_A 0
#define CONJUNTO_B 1



				/***************************************************************************************************************************************
				 * 												DECALRACIONES DE FUNCIONES AUXILIARES
				 ****************************************************************************************************************************************/
static void   init(void);
static void   cleanup(void);
static void   keyEvent( unsigned char key, int x, int y);
static void   mainLoop(void);
static void   draw();

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
    init();

    arVideoCapStart();
    argMainLoop( NULL, keyEvent, mainLoop );
	return (0);
}

static int cargarDeFichero(void) {
	FILE *fich;
	char c;
	fich=fopen("DataXO/conf.con","r");
	if(fich != NULL) {
		fscanf(fich," %c",&c);
		if(c=='#'){ //si el separador es correcto y no es fin de fichero carga valores;
			fscanf(fich,"%d",&minH);
			fscanf(fich,"%d",&maxH);
			fscanf(fich,"%d",&minS);
			fscanf(fich,"%d",&maxS);
			fscanf(fich,"%d",&minB);
			fscanf(fich,"%d",&maxB);
		}
		fclose(fich);
		printf("Configuracion HSV cargada:\n");
		printf("minH = %d , maxH = %d\n",minH,maxH);
		printf("minS = %d , maxS = %d\n",minS,maxS);
		printf("minB = %d , maxB = %d\n",minB,maxB);
		return 1;
	}else{
		printf("Se usaran los valores por defecto, el motivo es: No se puede leer el archivo de configuracion\n");
	}
	return 0;
}

static void   keyEvent( unsigned char key, int x, int y)
{
    /* quit if the ESC key is pressed */
    if( key == 0x1b ) {
        printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
        cleanup();
        exit(0);
    }


    if( key == 'v' ) {
		mostrarVideo = 1 - mostrarVideo;
		if(!mostrarVideo){
			argCleanWindow(0,0);
		}
    }

    if( key == 'c' ) {
		dibujarCubos = 1 - dibujarCubos;
		if(!dibujarCubos){
			argCleanWindow(0,0);
		}
	}

    if( key == 'r' ) {
		mostrarRadar = 1 - mostrarRadar;
		if(!mostrarRadar){
			argCleanWindow(2,1);
		}
	}

    if( key == 't' ) {
        printf("count = %d\n",count);
        printf("timer = %f\n",arUtilTimer());
        printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
        printf("Enter new threshold value (current = %d): ", thresh);
        scanf("%d",&thresh); while( getchar()!='\n' );
        printf("\n");
        count = 0;
    }

    /* turn on and off the debug mode with right mouse */
    if( key == 'd' ) {
        printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
        arDebug = 1 - arDebug;
        if( arDebug == 0 ) {
            glClearColor( 0.0, 0.0, 0.0, 0.0 );
            glClear(GL_COLOR_BUFFER_BIT);
            argSwapBuffers();
            glClear(GL_COLOR_BUFFER_BIT);
            argSwapBuffers();
        }
        count = 0;
    }

    if( key == '+' ) {
			minH += 5;
            printf("*** Aumento hue: %d", minH);
	}

    if( key == '-' ) {
			minH -= 5;
			printf("*** Disminuyo hue: %d", minH);
	}


}

/**
 * Recibe el indice del marcador no detectado y chequea si algun apuntador esta colisionando con el mismo.
 * Devuelve el area del apuntador detectado o 0 en caso de no haber detectado ninguno.
 */
float hayColision(int indiceMarcdor, ARUint8 *dataPtr){
//TODO Ver si es necesario crear la imagen opencv en color o solo con pasar del dataPtr alcanza para crear la mono y pasarsela al hayContorno
	int resultado[2];
	calcularPuntoOrigen(marcadoresOcultos[indiceMarcdor].vertex, resultado);

	float v0_x = marcadoresOcultos[indiceMarcdor].vertex[resultado[0]][0];
	float v0_y = marcadoresOcultos[indiceMarcdor].vertex[resultado[0]][1];
	float v2_x = marcadoresOcultos[indiceMarcdor].vertex[resultado[1]][0];
	float v2_y = marcadoresOcultos[indiceMarcdor].vertex[resultado[1]][1];

	int xStart = 0;
	if(v0_x>OFFSET_ROI){ //Chequeo para no salirme del ancho de la pantalla
		xStart = v0_x - OFFSET_ROI;
	}

	int yStart = 0;
	if(v0_y > OFFSET_ROI){ //Chequeo para no salirme del alto de la pantalla
		yStart = v0_y - OFFSET_ROI;
	}

	int widthZonaEstudio = abs( v2_x - xStart) + OFFSET_ROI;
	if(xStart + widthZonaEstudio > xsize){ //Chequeo para no salirme del ancho de la pantalla
		widthZonaEstudio = xsize - xStart;
	}

	int heightZonaEstudio = abs(v2_y - yStart) + OFFSET_ROI;
	if(yStart + heightZonaEstudio > ysize){ //Chequeo para no salirme del alto de la pantalla
		heightZonaEstudio = ysize - yStart;
	}

    cvSetImageData( img, (uchar*)(dataPtr), img->width* img->nChannels );
	img->origin = IPL_ORIGIN_TL;
	cvZero(mono_Image);							//FIXME Es necesario? Probar sin esto
	float area = -1;

	//Calculo el area de la zona de estudio. Segun este area vamos a obtener la cota minima y maxima del area del apuntador esperado segun la calibracion que se hay realizado
	//Por ejemplo si el apuntador ocupa 1/8 del marcador, y el area de la zona de estudio (que es aproximadamente el area del marcador) es de 800, entonces
	//buscaremos un apuntador de (800)*(1/8) = 100 +/- UMBRAL_AREA_APUNTADOR
	int areaZonaEstudio = heightZonaEstudio*widthZonaEstudio;

	if(heightZonaEstudio>MIN_AREA_WIDTH_HEIGHT  &&  widthZonaEstudio > MIN_AREA_WIDTH_HEIGHT){ //Ver definicion de MIN_AREA_WIDTH_HEIGHT para comprender mejor este chequeo
		//area = fabs(hayObjetoColor(img,mono_Image,minH,maxH,minS,maxS,minB,maxB,0,xStart,yStart,widthZonaEstudio,heightZonaEstudio,min_area,ERODE,DILATE));
		//FIXME Esta llamada es vieja, hay que cambiarla por una llamada a hayApuntador y reducir la logica de esta funcion
		area = fabs(hayObjetoColor(img,mono_Image,minH,maxH,minS,maxS,minB,maxB,
							 debugImg,xStart,yStart,widthZonaEstudio,heightZonaEstudio,min_area,10000,
							 ERODE,DILATE,SMOOTH,0,NULL,NULL));
		if(area>0){
			printf("Area zona estudio = %d\n",areaZonaEstudio);
			printf("Area apuntador = %f\n",area);
			/************************************************************************************************************
			 * 	DESCOMENTAR EL SIGUIENTE CODIGO PARA VER LOS SEGMENTOS DE IMAGEN EN LOS CUALES SE DETECTO EL APUNTADOR
			 *	mostrarTarget(img,xStart,yStart,widthZonaEstudio,heightZonaEstudio);
			 *	mostrarTarget(mono_Image,xStart,yStart,widthZonaEstudio,heightZonaEstudio);
			 * **********************************************************************************************************/
		}
	}
	return area;
}


void actualizarPantalla(){
	if(elementoConjuntoA!=-1 || elementoConjuntoB!=-1){

		if(elementoConjuntoA!=-1){

			if(elementos[elementoConjuntoA].idImagenSDL == idSDLImagenPantallaA && idSDLImagenPantallaA >= 0){
				printf("Se sigue seleccionando la misma imagen, no se hace nada");
			}else{
				if(idSDLImagenPantallaA!=-1){
					OcultarImage(idSDLImagenPantallaA,0);
				}
				if( (elementos[elementoConjuntoA].idImagenSDL == -1)  ){ //Todavia no se cargo la imagen para este elemento
					printf("voy a desplegar la imagen: %s\n",elementos[elementoConjuntoA].imagen);
					elementos[elementoConjuntoA].idImagenSDL = PlayImageConTitulo( elementos[elementoConjuntoA].imagen, elementos[elementoConjuntoA].nombre,xConjuntoA,yConjuntoA,0);
					idSDLImagenPantallaA = elementos[elementoConjuntoA].idImagenSDL; //Actualizo el id de la imagen mostrada actualmente
					printf("IdSDLA = %d\n",idSDLImagenPantallaA);
					PlaySound(clickSound);
				}else{
					mostrarImagen(elementos[elementoConjuntoA].idImagenSDL,0);
					idSDLImagenPantallaA = elementos[elementoConjuntoA].idImagenSDL;
					PlaySound(clickSound);
				}
			}
		}

		if(elementoConjuntoB!=-1){
			if(elementos[elementoConjuntoB].idImagenSDL == idSDLImagenPantallaB && idSDLImagenPantallaB > 0){
				printf("Se sigue seleccionando la misma imagen, no se hace nada");
			}else{
				if(idSDLImagenPantallaB!=-1){
					OcultarImage(idSDLImagenPantallaB,0);
				}
				if( (elementos[elementoConjuntoB].idImagenSDL == -1)  ){ //Todavia no se cargo la imagen para este elemento
					elementos[elementoConjuntoB].idImagenSDL = PlayImageConTitulo( elementos[elementoConjuntoB].imagen, elementos[elementoConjuntoB].nombre,xConjuntoB,yConjuntoB,0);
					idSDLImagenPantallaB = elementos[elementoConjuntoB].idImagenSDL; //Actualizo el id de la imagen mostrada actualmente
					PlaySound(clickSound);
				}else{
					mostrarImagen(elementos[elementoConjuntoB].idImagenSDL,0);
					idSDLImagenPantallaB = elementos[elementoConjuntoB].idImagenSDL;
					PlaySound(clickSound);
				}
			}
		}

		if(correspondenciaCorrecta){
			OcultarZona(xNombreRelacion,yNombreRelacion,anchoPantalla - xNombreRelacion,yConjuntoA - 5,0); //Borro la zona superior de la pantalla que es donde esta escrito el texto
			EscribirTexto(elementos[elementoConjuntoA].nombreRelacion,xNombreRelacion,yNombreRelacion,0);
			PlaySound(elementos[elementoConjuntoA].sonido);
		}else if(correspondenciaIncorrecta){
			PlaySound(errorSound);
		}

	}else{
		EscribirTexto("Prototipo - Estado Inicial",xNombreRelacion,yNombreRelacion,0);
	}
	//Actualizo la pantalla
	printf("Flip antes\n");
	flip();
	printf("Flip dsps\n");
}

void testearRegistroDeColisiones(){
	int cant = registrarColision(5,&historico);
	printf("cant = %d\n",cant);
	cant = registrarColision(5,&historico);
	printf("cant = %d\n",cant);
	cant = registrarColision(5,&historico);
	printf("cant = %d\n",cant);
	cant = registrarColision(5,&historico);
	printf("cant = %d\n",cant);
	cant = registrarColision(3,&historico);
	printf("cant = %d\n",cant);
}
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    double          err;
    int             i;


    /* grab a video frame */

    arUtilSleep(90000);
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
	printf("sleep\n");
	arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    if(img==NULL){
    	img = crearImagenCv2(dataPtr,xsize,ysize);
    }

    /* detect the markers in the video frame */
	if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
		cleanup();
		exit(0);
	}



	//argSwapBuffers();
	if(mostrarVideo){
		argDrawMode2D();
		if( !arDebug ) {
			argDispImage( dataPtr, 0,0 );
		}
		else {
			argDispImage( dataPtr, 1, 1 );
			if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
				argDispHalfImage( arImage, 0, 0 );
			else
				argDispImage( arImage, 0, 0);

			glColor3f( 1.0, 0.0, 0.0 );
			glLineWidth(6.0);
			for( i = 0; i < marker_num; i++ ) {
				argDrawSquare( marker_info[i].vertex, 0, 0 );
			}
			glLineWidth( 1.0 );
		}
	}

	if(mostrarRadar){
		argDrawMode2D();
		argCleanWindow(2,1);
		dibujarLimitesPantalla(xsize, ysize);
		for( i = 0; i < marker_num; i++ ) {
			dibujarMiniMarcador(0,0,marker_info[i].vertex,1);
		}
	}
    arVideoCapNext();

	if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
		argSwapBuffers();
		return;
	}

	if(err > 100.0 ) {
	  printf("saliendo 2\n");
	  argSwapBuffers();
	  return;
	}

	if(mostrarVideo || dibujarCubos){
		argDrawMode3D();
		argDraw3dCamera( 0, 0 );
		glClearDepth( 1.0 );
		glClear(GL_DEPTH_BUFFER_BIT);
	}
	//printf("Marcadores detectados = %d\n",marker_num);


	if(marker_num>0){
		for( i = 0; i < config->marker_num; i++ ) {
			if( (dibujarCubos)&&(config->marker[i].visible >= 0 )){
				draw( config->trans, config->marker[i].trans, 0 );
			}else {
				/*
				*		MARCADOR NO DETECTADO.
				*									* TENEMOS SUS COORDENADAS
				*														- Marker Coordinates (Xm,Ym)
				*														- Camera Coordinates (Xc,Yc)
				*									* NECESITAMOS SUS COORDENADAS
				*														- Ideal Screen Coordinates  (xc,yc)
				*
				*/
				double hXi_hYi[3][4];
				obtenerCoordenadasIdealesMarcadorNoDetectado(config->trans,config->marker[i],hXi_hYi,marcadoresOcultos[i].vertex);

				double Xi,Yi;
				if(hXi_hYi[2][3]!=0){ //TODO que pasa si h==0?
					marcadoresOcultos[i].centro[0] = hXi_hYi[0][3]/hXi_hYi[2][3];
					marcadoresOcultos[i].centro[1] = hXi_hYi[1][3]/hXi_hYi[2][3];
				}else{
					marcadoresOcultos[i].centro[0] =  hXi_hYi[0][3];
					marcadoresOcultos[i].centro[1] =  hXi_hYi[1][3];
				}

				if(dibujarCubos){
					dibujarPuntosMarcadorNoDetectado(Xi,Yi,marcadoresOcultos[i].vertex);
				}
				if(mostrarRadar){
					argDrawMode2D();
					dibujarMiniMarcador(0,0,marcadoresOcultos[i].vertex,0);
				}

				int area = hayColision(i,dataPtr);  //Chequea que algun apuntado este colisionando con el marcador i
				if(area>0){
					int cant = registrarColision(i,&historico);
					if(cant>=CANT_HISTORIA){
						correspondenciaCorrecta = 0;
						correspondenciaIncorrecta = 0;
						if(elementos[i].conjunto == CONJUNTO_A){
							//printf("es de conjunto A y ")
							elementoConjuntoA =config->marker[i].patt_id;
							elementoConjuntoB =-1;	//Dejo sin seleccionar elementos del conjunto B
						}else if(elementos[i].conjunto == CONJUNTO_B){
							if(elementoConjuntoA==-1){ //No hay elemento del conjunto A seleccionado previamente
								printf("PRIMERO SELECCIONAR ELEMENTO DEL CONJUNTO A\n");
							}else{
								elementoConjuntoB = config->marker[i].patt_id;
								if(elementos[elementoConjuntoA].idElementoRelacionado == elementos[elementoConjuntoB].idPatt){
									//Exito, se realizo la correspondencia correctamente
									correspondenciaCorrecta = 1;
									printf("EXITO!!!\n");
									printf("%s %s %s",elementos[elementoConjuntoA].nombre,elementos[elementoConjuntoA].nombreRelacion,elementos[elementoConjuntoB].nombre);
								}else{
									correspondenciaIncorrecta = 1;
								}
							}
						}else{
							fprintf(stderr, "Error, el elemento seleccionado no pertenece ni al conjunto A ni al B\n");
							cleanup();
							exit(0);
						}
						printf("&&&&&&&&&&& COLISION CON MARCADOR %d &&&&&&&&&&&&&&&\n",i);
						actualizarPantalla();
						break;				// Por ahora cuando se detecta la primera colision ya frenamos
					}else{
						printf("Colision nro %d con marcador %d\n",cant,i);
					}
				}

			}

		}
	}

	if(mostrarRadar || mostrarVideo || dibujarCubos){
		argSwapBuffers();
	}
}


static void init( void )
{
    ARParam  wparam;
    //Cargo configuracion del color a detectar
    cargarDeFichero();
    //Cargo archivo de configuracion de los elementos a detectar
    cantElementosCargados = leerConfiguracionElementos("prototipo1.config",elementos,MAX_MARCADORES,clickSound,errorSound);
    printf("Se cargaron %d elementos\n",cantElementosCargados);
    imprimirPropiedadesElementos(elementos,cantElementosCargados);
    /* open the video path */
    if( arVideoOpen( vconf ) < 0 ) exit(0);
    /* find the size of the window */
    if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
    printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
    if(xsize<500){
    	printf("min_area = %d\n", MIN_AREA/2);
    	min_area = MIN_AREA/2;
    }else{
    	printf("min_area = %d\n", MIN_AREA);
		min_area = MIN_AREA;
    }

    /* set the initial camera parameters */
    if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
        printf("Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    printf("*** Camera Parameter ***\n");
    arParamDisp( &cparam );

    if( (config = arMultiReadConfigFile(config_name)) == NULL ) {
        printf("config data load error !!\n");
        exit(0);
    }

    /* open the graphics window */
    argInit( &cparam, 1.0, 0, 2, 1, 0 );
    arFittingMode   = AR_FITTING_TO_INPUT;//AR_FITTING_TO_IDEAL;
    arImageProcMode = AR_IMAGE_PROC_IN_HALF;
    argDrawMode     = AR_DRAW_BY_TEXTURE_MAPPING;
    argTexmapMode   = AR_DRAW_TEXTURE_HALF_IMAGE;

    printf("Inicializo data e img\n");
    data1= new uchar[xsize* AR_PIX_SIZE_DEFAULT*ysize];   // Creo data1 del maximo tamanio que pueda necesitar
    img = crearImagenCv2(data1,xsize,ysize);  // Idem con la imagenCv
    mono_Image =cvCreateImage( cvGetSize(img), 8, 1 );

    //Inicializacion de sdl
	if(!initSDL(anchoPantalla,altoPantalla)){
		cleanup();
		exit(0);
	}
	CargarFondo("Data/prototipo1/fondoPrototipo1.bmp",1);


	//Inicializo historial
	initHistorico(&historico,CANT_HISTORIA,-1);

	//Inicialmente mostramos el radar
	//cleanup();
	//exit(0);
	//PlayImageConTitulo( elementos[0].imagen, elementos[0].nombre,xConjuntoA,yConjuntoA,0);
	//flip();
}

/* cleanup function called when program exits */
static void cleanup(void)
{
    arVideoCapStop();
    arVideoClose();
    argCleanup();
    cleanUpSDL();
}