diff options
Diffstat (limited to 'multi/SRC/RenataXO.cpp')
-rw-r--r-- | multi/SRC/RenataXO.cpp | 449 |
1 files changed, 0 insertions, 449 deletions
diff --git a/multi/SRC/RenataXO.cpp b/multi/SRC/RenataXO.cpp deleted file mode 100644 index 9eb3ea6..0000000 --- a/multi/SRC/RenataXO.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Renata.cpp - * - * Created on: 5/11/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 - *************************************************************************************************************************/ - - - /************************************************************************************************************************* - * CONFIGURACION DE RECONOCIMIENTO DE COLORES - *************************************************************************************************************************/ - - - /******************************************************************************************************************************** - * CONFIGURACION DE ARTOOLKIT Y MARCADORES - ********************************************************************************************************************************/ -int lite = 0; -#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; - -int mostrarVideo=1; - -/************************************************************************************************************************************** - * ************************************************************************************************************************************ - * VARIABLES DEL PROTOTIPO - * ************************************************************************************************************************************ - * ************************************************************************************************************************************/ -#define MIN_DETECCIONES 2 - -/* 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 -//2 Sonidos de error -char error1[255]; -char error2[255]; - -int cantElementosCargados = 0; - -int elementoActual = -1; //indice del elemento que esta en pantalla - -int xNombreRelacion = 200; -int yNombreRelacion = 15; - -int xImagen = 100; -int yImagen = 100; - -int anchoPantalla = 600; -int altoPantalla = 600; - -int idSDLImagenPantalla =-1; - - -int estado = 0; //0 indica que se esta esperando un marcador - //1 indica que se reproduce sonido - //2 indica que se termino el cuento - - -Historico historico; - -ARUint8 *dataPtr; -ARMarkerInfo *marker_info; -int marker_num; -double err; -int i; - - -//Marcadores habilitados para que la aplicacion los reconozca -char* patts[] = { "Data/renata/patterns/tortuga.patt", - "Data/renata/patterns/conejo.patt", - "Data/renata/patterns/elefante.patt", - "Data/renata/patterns/jirafa.patt", - "Data/renata/patterns/leon.patt", - "Data/renata/patterns/ardilla.patt"}; - -int* patts_id ; //El id del marcador es el indice del elemento al que corresponde en el arreglo elementos -int ayuda = 0; -int sdlInicializado = 0; - /*************************************************************************************************************************************** - * DECALRACIONES DE FUNCIONES AUXILIARES - ****************************************************************************************************************************************/ -static void init(void); -static void keyEvent( unsigned char key, int x, int y); -static void mainLoop(void); -static int cargarMarcadores(); - - -static int cargarMarcadores() -{ - int i ; - int idPatt = -1; - for(i=0;i<cantElementosCargados;i++){ - if(elementos[i].idPatt>=0){ - idPatt = arLoadPatt(patts[i]); - if (idPatt < 0) { - fprintf(stderr, "setupMarker(): pattern load error !!\n"); - return (0); - } - if(idPatt!=elementos[i].idPatt){ - fprintf(stderr, "Error en el orden de los elementos. elemento[%d].idPatt=%d , id devuelvo por arLoadPatt=%d!!\n",i,elementos[i].idPatt,idPatt); - return (0); - } - printf("Marcador id= %d cargado!\n",elementos[i].idPatt); - } - } - - return (1); -} - -//reproduce el audio en elementos[indice] -void reproducirSonidoEtapa(int indice){ - if(elementos[indice].sonido!=NULL){ - PlaySound(elementos[indice].sonido); - } -} - -//muestra la imagen de elementos[indice] -void mostrarImagenEtapa(int indice){ - if(idSDLImagenPantalla!=-1){ - OcultarImage(idSDLImagenPantalla,1); - } - if(elementos[indice].idImagenSDL<0){ - elementos[indice].idImagenSDL = PlayImageConTitulo( elementos[indice].imagen, elementos[indice].nombre,xImagen,yImagen,0); - }else{ - mostrarImagen(elementos[indice].idImagenSDL,0); - } - idSDLImagenPantalla = elementos[indice].idImagenSDL; //Actualizo el id de la imagen mostrada actualmente - flip(); -} - -int main(int argc, char **argv) -{ - glutInit(&argc, argv); - init(); - arVideoCapStart(); - argMainLoop( NULL, keyEvent, mainLoop ); - return (0); -} - -void avanzar(){ - printf("Avanzar\n"); - printf("elementoActual=%d, cantElementosCargados-1=%d\n",elementoActual,cantElementosCargados-1); - if(estado==1){ //termino de reproducir parte del cuento. - estado =0; - }else{ - if(elementoActual == cantElementosCargados -1){//TODO Vuelve a comenzar o mensaje de exito y finaliza?? - printf("FIN DEL CUENTOOOOOOOOOOOOOOOOO!\n"); - estado=2; - }else{ - estado=1; - elementoActual++; - } - } - -} - -/* main loop */ -static int procesarFrame() -{ - ARUint8 *dataPtr; - ARMarkerInfo *marker_info; - int marker_num; - double err; - int i; - - //arVideoCapStart(); - if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) { - printf("sleep\n"); - arUtilSleep(2); - return -1; - } - if( count == 0 ) arUtilTimerReset(); - count++; - - /* ATENCION, DETECTMARKERLITE ES MAS RAPIDA PERO TIENE MAS ERROR QUE DETECTMARKER */ - if(lite){ - /* detect the markers in the video frame */ - if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) { - cleanupAll(); - exit(0); - } - }else{ - if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) { - cleanupAll(); - exit(0); - } - } - - 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 ); - } - } - - argSwapBuffers(); - - int j; - int indice = -1; - if(marker_num>0){ - printf(" *marcadores detectados = %d \n",marker_num); - } - - - //Busco algun marcador que se haya cargado en elementos[] - for(j = 0;(j<marker_num);j++){ - printf("marker_info[%d]=%d\n",j,marker_info[j].id); - printf("marker_info[%d].cf=%f\n",j,marker_info[j].cf); - int k; - if(marker_info[j].cf > 0.60){ - for(k=0;k<cantElementosCargados;k++){ - if(elementos[k].idPatt>=0 && marker_info[j].id==elementos[k].idPatt){ //Elije el primer marcador con el mismo id, no el que mas se parezca usando el cf - printf("patt %d detectado!\n",marker_info[j].id); - return elementos[k].idPatt; - } - } - } - } - - - return -1; -} - -void reproducirAyuda(Elemento elemento){ - ayuda =!ayuda; - if(ayuda==0 && error1!=NULL){ - PlaySound(error1); - }else if(ayuda==1 && error1!=NULL){ - PlaySound(error2); - } -} - -static void mainLoop(void){ - if(!sdlInicializado){ - if(!initSDL(anchoPantalla,altoPantalla)){ - cleanupAll(); - exit(0); - } - CargarFondo("Data/renata/imagenes/fondoRenata.bmp",1); - sdlInicializado = 1; - } - switch (estado) { - case 0: - arVideoCapStart(); - if(elementos[elementoActual].idPatt>=0){ - int idMarcadorEncontrado = procesarFrame(); - if(idMarcadorEncontrado>=0){ - int cant =registrarColision(idMarcadorEncontrado,&historico); - if(cant>=MIN_DETECCIONES){ // Ya detecto el marcador suficientes veces y se da por valido. - if(idMarcadorEncontrado==elementoActual){ - mostrarImagenEtapa(elementoActual); //Se despliega la imagen correspondiente a esta etapa del cuento y se cambia el - avanzar(); //estado para que continue reproduciendo el sonido del cuento. - }else{ - reproducirAyuda(elementos[elementoActual]); - } - initHistorico(&historico,MIN_DETECCIONES,-1); - } - - } - arVideoCapNext(); - }else{ //En esta etapa no se espera ningun marcador - mostrarImagenEtapa(elementoActual); //Se despliega la imagen correspondiente a esta etapa del cuento y se cambia el - avanzar(); //estado para que continue reproduciendo el sonido del cuento. - } - break; - case 1: //reproducir sonido de la etapa - arVideoCapStop(); - reproducirSonidoEtapa(elementoActual); - avanzar(); - break; - case 2: - //TODO alguna accion cuando termina el cuento? - sleep(2); - cleanupAll(); - exit(0); - break; - default: - fprintf(stderr, "Estado de aplicacion invalido\n"); - exit(1); - break; - } - - -} - -static void init( void ) -{ - ARParam wparam; - //Cargo archivo de configuracion de los elementos a detectar - cantElementosCargados = leerConfiguracionElementos("renata.config",elementos,MAX_MARCADORES,error1,error2); - 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); - - /* 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 ); - - //Mostramos la imagen de debug desde el principio - arDebug = 1; - - - /* open the graphics window */ - argInit( &cparam, 1.0, 0, 2, 1, 0 ); - arFittingMode = AR_FITTING_TO_IDEAL; - arImageProcMode = AR_IMAGE_PROC_IN_FULL; - argDrawMode = AR_DRAW_BY_TEXTURE_MAPPING; - argTexmapMode = AR_DRAW_TEXTURE_HALF_IMAGE; - - //Inicializacion de sdl - /*if(!initSDL(anchoPantalla,altoPantalla)){ - cleanupAll(); - exit(0); - }*/ - - //Cargo patterns - if(!cargarMarcadores()){ - cleanupAll(); - fprintf(stderr, "Error cargando patterns\n"); - exit(0); - } - //Inicializo historial - initHistorico(&historico,MIN_DETECCIONES,-1); - elementoActual = 0; - estado = 1; - //La imagen del elemento 0 es el fondo de la pantalla :) -// CargarFondo("Data/renata/imagenes/fondoRenata.bmp",1); -} - - - -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()); - cleanupAll(); - exit(0); - } - - if( key == 'v' ) { - mostrarVideo = 1 - mostrarVideo; - if(!mostrarVideo){ - argCleanWindow(0,0); - } - } - - if( key == SDLK_RETURN ) { //Avanza sin que haya reconocido el marcador - if(estado==0){ //Si se esta esperando un marcador y se toca enter, entonces salta automaticamente y cambia el estado para seguir - mostrarImagenEtapa(elementoActual); - avanzar(); //reproduciendo el sonido de la proxima etapa. - } - - } - - 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; - } - -} |