diff options
author | pgperui <pgperui@65703dd9-322d-4ecd-a169-f49c4620ba53> | 2011-07-07 05:00:27 (GMT) |
---|---|---|
committer | pgperui <pgperui@65703dd9-322d-4ecd-a169-f49c4620ba53> | 2011-07-07 05:00:27 (GMT) |
commit | cf890f426b82a517c6875e5e16bfb663618a6300 (patch) | |
tree | 04f06d3670cf24ebf8d550946599b6c75bb396ce /Utilidades/bin/python/TocarAnimalesPUI.py | |
parent | 1f7f401a8111ab32b83af6dedda991ebe1efcdfe (diff) |
git-svn-id: svn+ssh://lulu.fing.edu.uy/ens/home01/pgperui/repoSVN@190 65703dd9-322d-4ecd-a169-f49c4620ba53
Diffstat (limited to 'Utilidades/bin/python/TocarAnimalesPUI.py')
-rw-r--r-- | Utilidades/bin/python/TocarAnimalesPUI.py | 161 |
1 files changed, 117 insertions, 44 deletions
diff --git a/Utilidades/bin/python/TocarAnimalesPUI.py b/Utilidades/bin/python/TocarAnimalesPUI.py index 67977ba..4e4296b 100644 --- a/Utilidades/bin/python/TocarAnimalesPUI.py +++ b/Utilidades/bin/python/TocarAnimalesPUI.py @@ -1,7 +1,8 @@ #! /usr/bin/env python -import pygame, sys, os, time +import pygame, sys, os, time,gobject 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" @@ -18,8 +19,10 @@ usarAlgoritmoRapido = 1 mostrarDebugAR = 0 idObjetoPUISeleccionado = -1 idObjetoPUIActual = -1 +correspondenciaCorrecta =False frameSize = (320,240) +mostrarVideo=1 err_deteccion = 0 @@ -37,8 +40,65 @@ 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) # +# | # +# Radar | # +# | # +#(480,0)---------------------------------------(640,480) +def actualizarPantalla(): + global idObjetoPUIActual,surface,pui,correspondenciaCorrecta + print '**********actualizarPantalla!!**********\n' + if not idObjetoPUIActual==-1: + print '%%%%%%%%%%%%%DIBUJO!%%%%%%%%%' + #print pui.getImagenObjetoPUI(idObjetoPUIActual) + 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,(415,400)) + pygame.display.flip() + print '%%%%%%%%%%%%%listo!%%%%%%%%%' + if correspondenciaCorrecta: + pygame.mixer.music.load(pui.getSonidoObjetoPUI(idObjetoPUIActual)) + pygame.mixer.music.play() + +def mostrarStatus(): + global screen,cantElementosCargados,pui,display + cant_visibles = 0 + for i in range(cantElementosCargados): + print 'i=%d'%i + infoMarcador = pui.getInfoMultiMarcador(i) + if infoMarcador.visible: + cant_visibles=cant_visibles + 1 + pygame.draw.rect(display.get_surface(), (0,0,0), (320,320,320,160),0) + print 'antes!' + #nombre = pui.getNombreObjetoPUI(0) + nombre = 'Status...' + print nombre + status_surface = pygame.font.Font(None,80).render(str(cant_visibles),1,(255,0,0)) + #status_surface = pygame.font.Font(None,20).render("blabalbal") + print 'dsps!' + screen.blit(status_surface,(50,400)) + pygame.display.flip() + +def proximoElemento(): + global cantElementosCargados,idObjetoPUIActual + if idObjetoPUIActual == cantElementosCargados -1: + idObjetoPUIActual = 0 + else: + idObjetoPUIActual = idObjetoPUIActual +1 + + def desplegarDataImage(imageData): - global running,screen,frameSize,aplicar_mascara,aplicar_nueva_mascara,tipoMascara,pui,mostrarDebugAR,tomar_muestra + global running,screen,frameSize,mostrarDebugAR,mostrarVideo print '14' pg_img = pygame.image.frombuffer(imageData,frameSize, "RGB") print '15' @@ -46,50 +106,43 @@ def desplegarDataImage(imageData): pygame.display.flip() print '16' 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_a: #aplicar mascara - aplicar_mascara = 1 - aplicar_mascara - elif event.key == K_n: #nueva mascara - aplicar_nueva_mascara = 1 - aplicar_nueva_mascara; - aplicar_mascara = 1; - elif event.key == K_u: #tipo de mascara - if tipoMascara==PuiModule.TIPO_MASCARA_BINARIA : - tipoMascara=PuiModule.TIPO_MASCARA_ATENUANTE - print 'Usando mascara ATENUANTE!\n' - else: - tipoMascara=PuiModule.TIPO_MASCARA_BINARIA; - print 'Usando mascara BINARIA!\n' - elif event.key == K_t: #set threshold - print '*** %s (frame/sec)\n' % (pui.getFPS()) - 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 - pui.desplegarImagenAR(mostrarDebugAR) - elif event.key == K_RETURN: - tomar_muestra = 1 - aplicar_nueva_mascara = 1 - aplicar_nueva_mascara - aplicar_mascara = 1 + 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 '*** %s (frame/sec)\n' % (pui.getFPS()) + 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 + #pui.desplegarImagenAR(mostrarDebugAR) + elif event.key == K_PLUS: + pui.setHminApuntador(pui.getHminApuntador()+5) + pui.setHmaxApuntador(pui.getHmaxApuntador()+5) + print '*** Aumento hue: ['%pui.getHminApuntador()%','%pui.getHmaxApuntador()%']\n' + elif event.key == K_MINUS: + pui.setHminApuntador(pui.getHminApuntador()-5) + pui.setHmaxApuntador(pui.getHmaxApuntador()-5) + print '*** Disminuyo hue: ['%pui.getHminApuntador()%','%pui.getHmaxApuntador()%']\n' else: print 'Evento desconocido!' - - - - def main(): - global pui,running,cantElementosCargados,cant_historia,usarAlgoritmoRapido,calibracion_apuntador,config_multi_markers,cparam_name,vconf,err_deteccion,idObjetoPUISeleccionado + global 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' - pui.initPuiConCapturaDeVideo(PuiModule.MODO_MULTI_MARKERS,calibracion_apuntador,config_multi_markers,cparam_name,vconf,usarAlgoritmoRapido,pui.NORMAL_SPEED_LOOP,1.0); print '2\n' @@ -98,19 +151,30 @@ def main(): pui.capStart() cantElementosCargados = pui.leerConfiguracionObjetosPUI("Data/TocarAnimalesPUI/ObjetosPuiTocarAnimales.config",10); - print 'Se cargaron ' % cantElementosCargados % ' elementos' + print 'Se cargaron %s elementos\n' % cantElementosCargados pui.imprimirPropiedadesObjetosPUI(); print '3\n' + #inicializo modulo de fuentes-->se inicializa todo en pygame.init + #pygame.font.init() + #pygame.mixer.init() + #pygame.display.init() + idObjetoPUIActual=0 + actualizarPantalla() + + while running: dataImagen = pui.capturarPyImageAR() #capturo imagen err_deteccion = pui.detectarYCalcularPosicionTodosMultiMarkers() #Detecto los marcadores y calculo las posiciones if err_deteccion==PuiModule.DETECCION_CORRECTA: #No hubo error al detectar los marcadores idObjetoPUISeleccionado = pui.detectarSeleccion() if idObjetoPUISeleccionado >= 0: - print '&&&&&&&&&&& COLISION CON MARCADOR ' %idObjetoPUISeleccionado % ' &&&&&&&&&&&&&&&' - correspondenciaCorrecta = pui.esRelacionCorrecta(idObjetoPUIActual,idObjetoPUISeleccionado) + print '&&&&&&&&&&& COLISION CON MARCADOR %d &&&&&&&&&&&&&&&' %idObjetoPUISeleccionado + #En este caso se corrobora que el objeto PUI seleccinoado corresponda con el objeto PUI representado en + #pantalla. En caso de que se utilicen objetos relacionados se puede preguntar por la relacion entre ellos + #de la siguiente manera pui.esRelacionCorrecta(idObjetoPUIActual,idObjetoPUISeleccionado) + correspondenciaCorrecta = idObjetoPUISeleccionado==idObjetoPUIActual actualizarPantalla() #A continuacion se muestran los diferentes codigos de error que pueden ser devueltos por PUI #elif err_deteccion == PuiModule.ERROR_NINGUN_MARCADOR_DETECTADO: @@ -129,9 +193,18 @@ def main(): if not dataImagen == None: #si se pudo obtener el frame entonces continuo desplegarDataImage(dataImagen.data) print '15' + mostrarStatus() pui.capNext() - + else: + print 'IMAGEN NULL, NO HAGO NADA!' + #except Exception: + # print "Excepcion recibida" if __name__ == "__main__": - main() + pygame.init() + gobject.threads_init() + main() + pygame.quit() + pui.finish() + print 'Fin del programa!!'
\ No newline at end of file |