From 9cf49252603c7af6c31ab4d012a7379db48223ba Mon Sep 17 00:00:00 2001 From: pgperui Date: Mon, 05 Sep 2011 05:08:33 +0000 Subject: git-svn-id: svn+ssh://lulu.fing.edu.uy/ens/home01/pgperui/repoSVN@203 65703dd9-322d-4ecd-a169-f49c4620ba53 --- diff --git a/Utilidades/bin/python/CalibradorColor.py b/Utilidades/bin/python/CalibradorColor.py index c62269e..724e7c0 100644 --- a/Utilidades/bin/python/CalibradorColor.py +++ b/Utilidades/bin/python/CalibradorColor.py @@ -1,9 +1,9 @@ #! /usr/bin/env python -# @author Sebastián Marichal +# @author Sebastian Marichal # sebastian_marichal@hotmail.com # sebarocker@gmail.com # -# Universidad de la República, Montevideo , Uruguay +# Universidad de la Republica, Montevideo , Uruguay # import pygame, sys, os, time, gobject import PuiModule @@ -42,11 +42,13 @@ dataImagen = None running = True esperar = True - +primera = True +zoom = None #Variables de pantalla size = (640,480) screen = pygame.display.set_mode(size) -surface = pygame.display.get_surface() +surface = pygame.display.get_surface() + def initRangosColor(): global rangosEscalaColor @@ -65,13 +67,19 @@ def desplegarRangosColor(rangos): print '--------------------------------\n' def desplegarDataImage(imageData): - global esperar,running,screen,frameSize,aplicar_mascara,aplicar_nueva_mascara,tipoMascara,pui,mostrarDebugAR,tomar_muestra + global zoom,primera,esperar,running,screen,frameSize,aplicar_mascara,aplicar_nueva_mascara,tipoMascara,pui,mostrarDebugAR,tomar_muestra print '14' pg_img = pygame.image.frombuffer(imageData,frameSize, "RGB") - print '15' - screen.blit(pg_img, (0,0)) + + print '15' + if primera: + zoom = transform.scale2x(pg_img) + primera = False + else: + transform.scale2x(pg_img,zoom) + screen.blit(zoom, (0,0)) + #screen.blit(pg_img, (0,0)) pygame.display.flip() - print '16' for event in pygame.event.get(): if event.type == pygame.QUIT: diff --git a/Utilidades/bin/python/MostrarAnimalesPUI.py b/Utilidades/bin/python/MostrarAnimalesPUI.py new file mode 100644 index 0000000..3bc4711 --- /dev/null +++ b/Utilidades/bin/python/MostrarAnimalesPUI.py @@ -0,0 +1,144 @@ +#! /usr/bin/env python +# @author Sebastian Marichal +# sebastian_marichal@hotmail.com +# sebarocker@gmail.com +# +# Universidad de la Republica, Montevideo , Uruguay +# +import pygame, sys, os, time,gobject +from time import sleep +import PuiModule +from pygame import * + +#Configuracion del pipeline de Gstreamer +vconf = "v4l2src device=/dev/video0 ! videorate ! video/x-raw-yuv,width=320,height=240,framerate=5/1 ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24 ! identity name=artoolkit ! fakesink" +#Archivo de configuracion Multi Marker de Artoolkit. Define la posicion relativa de los marcadores +config_name = "Data/MostrarAnimalesPUI/mostrarAnimales_ModoSimple.patterns" +#Archivo de calibracion de la camara, siempre usamos el mismo y no ha presentado problemas +cparam_name = "Data/camera_para.dat" + +cant_historia = 4 +usarAlgoritmoRapido = 1 +mostrarDebugAR = 0 + +idObjetoPUIActual = -1 + +frameSize = (320,240) +mostrarVideo=1 + +err_deteccion = 0 + +thresh = 100 + +pui = None +dataImagen = None + +running = True + +#Variables de pantalla +size = (640,480) +screen = pygame.display.set_mode(size) +surface = pygame.display.get_surface() + +# +#(0,0)------(320,0)------------------------------(640,0) +# | # +# Salida Video | # +# | Imagenes Animales # +#-----------(320,240) # +# | # +# | # +# | # +#(480,0)---------------------------------------(640,480) +def actualizarPantalla(): + global idObjetoPUIActual,surface,pui + print '**********actualizarPantalla!!**********\n' + if not idObjetoPUIActual==-1: + print '%%%%%%%%%%%%%DIBUJO!%%%%%%%%%' + img_surface =pygame.image.load(pui.getImagenObjetoPUI(idObjetoPUIActual)) + if img_surface.get_width > 320 or img_surface.get_height > 320: + img_surface = pygame.transform.scale(img_surface,(320,320)) + screen.blit(img_surface, (320,0)) + #idem pero con el nombre + pygame.draw.rect(display.get_surface(), (0,255,0), (320,320,320,160),0) + nombre_surface = pygame.font.Font(None,80).render(pui.getNombreObjetoPUI(idObjetoPUIActual),1,(255,0,0)) + screen.blit(nombre_surface,(410,380)) + pygame.display.flip() + + sound = pui.getSonidoObjetoPUI(idObjetoPUIActual) + print "****************************************Reproduccion del sonido " + sound + pygame.mixer.music.load(pui.getSonidoObjetoPUI(idObjetoPUIActual)) + pygame.mixer.music.play() + sleep(1.0) + + +def desplegarDataImage(imageData): + global running,screen,frameSize,mostrarDebugAR,mostrarVideo + pg_img = pygame.image.frombuffer(imageData,frameSize, "RGB") + screen.blit(pg_img, (0,0)) + pygame.display.flip() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + running = False + elif event.key == K_v: #mostrar video + mostrarVideo = 1 - mostrarVideo + elif event.key == K_RETURN: #Proximo elemento + proximoElemento() + actualizarPantalla() + elif event.key == K_t: #set threshold + print 'Threshold Actual = %s' % ( pui.getARThreshold() ) + user_input = input('*************** Ingrese nuevo Threshold ******************') + print 'Threshold ingresado = %s' % (user_input) + pui.setARThreshold(user_input) + elif event.key == K_d: #set debug image + mostrarDebugAR = 1 - mostrarDebugAR + +def main(): + global screen,pui,running,cant_historia,usarAlgoritmoRapido,config_name,cparam_name,vconf,err_deteccion,idObjetoDetectado,idObjetoPUIActual + + pui = PuiModule.Pui() + pui.setDebugMode(1) + print '1\n' + pui.initPuiConCapturaDeVideo(PuiModule.MODO_SIMPLE,None,config_name,cparam_name,vconf,usarAlgoritmoRapido,pui.NORMAL_SPEED_LOOP,1.0); + print '2\n' + #Si queremos usar la funcionalidad de PUI para desplegar el video tenemos que abrir la ventana grafica + #pui.abrirVentanaGrafica() + + pui.capStart() + cantElementosCargados = pui.leerConfiguracionObjetosPUI("Data/MostrarAnimalesPUI/mostrarAnimales_ModoSimple.objetosPUI",10); + print 'Se cargaron %s elementos\n' % cantElementosCargados + + pui.imprimirPropiedadesObjetosPUI(); + print '3\n' + + #Habilito funcion de historico. Al detectar 5 selecciones seguidas recien se cuenta como una seleccion real + pui.habilitarHistorico(True,5,-1) + + while running: + dataImagen = pui.capturarPyImageAR() #capturo imagen + err_deteccion = pui.detectarMarcadoresSimple() #Detecto marcador + if err_deteccion==PuiModule.DETECCION_CORRECTA: #No hubo error al detectar los marcadores + idObjetoDetectado = pui.getIdMarcadorSimpleDetectado() + if idObjetoDetectado >= 0: + print '&&&&&&&&&&& MARCADOR %d DETECTADO &&&&&&&&&&&&&&&' %idObjetoDetectado + idObjetoPUIActual = idObjetoDetectado; + actualizarPantalla() + if mostrarDebugAR: + debugImg = pui.obtenerPyImagenDebugAR() + if not debugImg== None: + desplegarDataImage(debugImg.data) + elif not dataImagen == None: #si se pudo obtener el frame entonces continuo: + desplegarDataImage(dataImagen.data) + pui.capNext() + + +if __name__ == "__main__": + pygame.init() + gobject.threads_init() + main() + pygame.quit() + pui.finish() + print 'Fin del programa!!' \ No newline at end of file diff --git a/Utilidades/bin/python/TocarAnimalesPUI.py b/Utilidades/bin/python/TocarAnimalesPUI.py index 334d60a..98c3d4c 100644 --- a/Utilidades/bin/python/TocarAnimalesPUI.py +++ b/Utilidades/bin/python/TocarAnimalesPUI.py @@ -1,14 +1,14 @@ #! /usr/bin/env python -# @author Sebastián Marichal +# @author Sebastian Marichal # sebastian_marichal@hotmail.com # sebarocker@gmail.com # -# Universidad de la República, Montevideo , Uruguay +# Universidad de la Republica, Montevideo , Uruguay # import pygame, sys, os, time,gobject +from time import sleep import PuiModule from pygame import * -from pychecker.msgs import CATCH_BAD_EXCEPTION #Configuracion del pipeline de Gstreamer vconf = "v4l2src device=/dev/video0 ! videorate ! video/x-raw-yuv,width=320,height=240,framerate=5/1 ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24 ! identity name=artoolkit ! fakesink" @@ -75,6 +75,7 @@ def actualizarPantalla(): print "****************************************Reproduccion del sonido " + sound pygame.mixer.music.load(pui.getSonidoObjetoPUI(idObjetoPUIActual)) pygame.mixer.music.play() + sleep(1.0) def mostrarStatus(): global screen,cantElementosCargados,pui,display @@ -139,7 +140,6 @@ def desplegarDataImage(imageData): def main(): global screen,pui,running,cantElementosCargados,cant_historia,usarAlgoritmoRapido,calibracion_apuntador,config_multi_markers,cparam_name,vconf,err_deteccion,idObjetoPUISeleccionado,idObjetoPUIActual,correspondenciaCorrecta - #try: pui = PuiModule.Pui() pui.setDebugMode(1) print '1\n' @@ -156,10 +156,9 @@ def main(): pui.imprimirPropiedadesObjetosPUI(); print '3\n' - #inicializo modulo de fuentes-->se inicializa todo en pygame.init - #pygame.font.init() - #pygame.mixer.init() - #pygame.display.init() + #Habilito funcion de historico. Al detectar 5 selecciones seguidas recien se cuenta como una seleccion real + pui.habilitarHistorico(True,5,-1) + idObjetoPUIActual=0 actualizarPantalla() status_surface = pygame.font.Font(None,40).render('-Marcadores Visibles-',1,(255,0,0)) @@ -198,10 +197,7 @@ def main(): mostrarStatus() pui.capNext() else: - print 'IMAGEN NULL, NO HAGO NADA!' - #except Exception: - # print "Excepcion recibida" - + print 'IMAGEN NULL, NO HAGO NADA!' if __name__ == "__main__": pygame.init() diff --git a/Utilidades/src/Pui.cpp b/Utilidades/src/Pui.cpp index be4d72d..0cd221c 100644 --- a/Utilidades/src/Pui.cpp +++ b/Utilidades/src/Pui.cpp @@ -1342,6 +1342,17 @@ unsigned char* Pui::capturarImagenAR(){ return (unsigned char*)this->dataArtoolkit.dataPtr; } +binary_data Pui::obtenerPyImagenDebugAR(){ + arDebug=true; + if (arImage!=NULL){ + memcpy(data,arImage,length); + result.data=data; + }else{ + result.data = NULL; + } + result.size = result.data==NULL?0:length; + return result; +} unsigned char* Pui::obtenerImagenDebugAR(){ return arImage; @@ -1886,7 +1897,7 @@ int Pui::cargarConfiguracionDeteccionApuntadorDesdeArchivo(char * fileName) { return 1; }else{ - printf("Se usaran los valores por defecto, el motivo es: No se puede leer el archivo de configuracion\n"); + printf("No se puede leer el archivo de configuracion\n"); } return 0; } diff --git a/Utilidades/src/Pui.h b/Utilidades/src/Pui.h index 796425e..68c5461 100644 --- a/Utilidades/src/Pui.h +++ b/Utilidades/src/Pui.h @@ -742,7 +742,7 @@ public: //TODO Incluir la funcionalidad que retorna la imagen de debug para Python //Implementacion analoga a capturarPyImageAR - //binary_data* obtenerPyImagenDebugAR(); + binary_data obtenerPyImagenDebugAR(); /*******************************************************************************************/ diff --git a/Utilidades/src/Pui.i b/Utilidades/src/Pui.i index 2cdf9c3..35e514f 100644 --- a/Utilidades/src/Pui.i +++ b/Utilidades/src/Pui.i @@ -48,7 +48,6 @@ binary_data bin_data = $1; int size = bin_data.size; if(size==0){ - printf("En typemap devolviendo vacio, size=0\n"); return Py_BuildValue(""); } /* para crear el array en un espacio de memoria compartida ya creado y pasado por parametro @@ -58,7 +57,6 @@ PyArrayObject *array = (PyArrayObject *) PyArray_FromDims(1, &size,PyArray_UBYTE); if (array == NULL){ - printf("En typemap devolviendo vacio,array=null\n"); PyErr_SetString(PyExc_ValueError,"Error creando PyArray"); return Py_BuildValue(""); } @@ -541,19 +539,7 @@ public: */ binary_data capturarPyImageAR(); - /** - * Retorna la imagen de debug utilizada por artoolkit. - * No se debe trabajar sobre esta imagen. Es de uso interno - * de artoolkit. - * - * Es recomendable hacer una copia de los datos antes de realizar - * cualquier modificacion - */ - unsigned char* obtenerImagenDebugAR(); - - //TODO Incluir la funcionalidad que retorna la imagen de debug para Python - //Implementacion analoga a capturarPyImageAR - //binary_data* obtenerPyImagenDebugAR(); + binary_data obtenerPyImagenDebugAR(); /*******************************************************************************************/ -- cgit v0.9.1