Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Utilidades
diff options
context:
space:
mode:
authorpgperui <pgperui@65703dd9-322d-4ecd-a169-f49c4620ba53>2011-05-02 01:12:03 (GMT)
committer pgperui <pgperui@65703dd9-322d-4ecd-a169-f49c4620ba53>2011-05-02 01:12:03 (GMT)
commit614225fde2b8994d443572d9ff00c00989c6463f (patch)
tree8fbede3d64c8462bd865c9cbe97cafb1a869fd66 /Utilidades
parent2f25374c951c1834c5b6d12bc49cb3a480a38eea (diff)
git-svn-id: svn+ssh://lulu.fing.edu.uy/ens/home01/pgperui/repoSVN@152 65703dd9-322d-4ecd-a169-f49c4620ba53
Diffstat (limited to 'Utilidades')
-rw-r--r--Utilidades/src/CalibradorColor.py110
-rw-r--r--Utilidades/src/Pui.cpp5
-rw-r--r--Utilidades/src/Pui.i8
-rw-r--r--Utilidades/src/PuiModule.py4
-rw-r--r--Utilidades/src/PuiModule.pycbin23968 -> 24240 bytes
-rw-r--r--Utilidades/src/Pui_wrap.cxx35
-rw-r--r--Utilidades/src/prueba.py86
7 files changed, 132 insertions, 116 deletions
diff --git a/Utilidades/src/CalibradorColor.py b/Utilidades/src/CalibradorColor.py
index acf5ed8..40c0c9c 100644
--- a/Utilidades/src/CalibradorColor.py
+++ b/Utilidades/src/CalibradorColor.py
@@ -1,23 +1,23 @@
#! /usr/bin/env python
import pygame, sys, os, time, opencv
import PuiModule
+from pygame import *
from opencv import *
from opencv.highgui import *
-vconf = ""
+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"
count = 0
config_nameCalibrador = "../bin/Data/multi/marker.dat"
rangosEscalaColor = PuiModule.RangosColorApuntador
usarAlgoritmoRapido = 1
mostrarDebugAR = 0
aplicarMascara = 0
-frameSize = (640,480)
+frameSize = (320,240)
h_bins = 30 #El histograma de HUE lo dividimos en 30 partes iguales
s_bins = 20 #El histograma de SATURATION lo dividimos en 20 partes iguales
v_bins = 20 #El histograma de BRIGHTNESS lo dividimos en 20 partes iguales
-#FIXME hay que seleccionar los marcadores de manera no secuencial y que no se repitan. Por el momento comienza en 0 y se va incrementando de a 1
id_marcador =0
tipoMascara = PuiModule.TIPO_MASCARA_BINARIA
err_deteccion = 0
@@ -39,9 +39,9 @@ dataImagen = None
running = True
#Variables de pantalla
-size = (1200,900)
-#screen = pygame.display.set_mode(size)
-#surface = pygame.display.get_surface()
+size = (640,480)
+screen = pygame.display.set_mode(size)
+surface = pygame.display.get_surface()
def initRangosColor():
rangosEscalaColor.hmin = 1 #Teoricamente seria correcto que hmin fuera 0. Lo ponemos en 1
@@ -59,67 +59,68 @@ def desplegarRangosColor(rangos):
print '--------------------------------\n'
def desplegarDataImage(imageData):
- global running
- global screen
- global frameSize
+ global 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))
-
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
-
-def desplegarImagenCV(imageData):
- global running
- sizeCv=CvSize()
- sizeCv.width = 640
- sizeCv.height = 480
-
- image = cv.cvCreateImage(sizeCv, cv.IPL_DEPTH_8U, 3)
- #cv.cvSetImageData( image,imageData, sizeCv.width * 3 )
- image.imageData = imageData # set data
- cvNamedWindow("image", 1)
- cvShowImage("image", image)
- #char= cvWaitKey(33)
- print '14';
- #if char != -1:
- # if ord(char) == 27:
- # running = False
-
- #cvDestroyWindow("image")
-
+ 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
+ else:
+ print 'Evento desconocido!'
+
+
def calibrar():
- global tomar_muestra
- global pui
- global id_marcador
- global muestra
- global aplicar_mascara
- global aplicar_nueva_mascara
- global tipoMascara
- global mostrarDebugAR
+ global tomar_muestra,pui, id_marcador, muestra, aplicar_mascara, aplicar_nueva_mascara, tipoMascara, mostrarDebugAR
print '7\n'
if tomar_muestra:
print 'Tomo la muestra!!!!!\n'
err_tomarMuestra = pui.tomarMuestraApuntador()
-
if err_tomarMuestra==PuiModule.ERROR_TOMAR_MUESTRA_FORMA_NO_IMPLEMENTADA:
sys.stderr.write("Error, no se pudo tomar muestra. Forma no implementada\n")
elif err_tomarMuestra==PuiModule.ERROR_TOMAR_MUESTRA_OK:
print 'Muestra tomada OK\n'
tomar_muestra=0
- id_marcador+=1 #FIXME no se debe incrementar asi porque se va a seleccionar de alguna manera mas inteligente, capaz aleatorio
+ id_marcador+=1
muestra+=1
else:
print '8\n'
- dataImagen = pui.capturarImagenAR()
+ dataImagen = pui.capturarPyImageAR()
print '9\n'
if aplicar_mascara:
if aplicar_nueva_mascara: #Calculo la nueva mascara y la aplico
@@ -141,27 +142,16 @@ def calibrar():
else: #No calculo nueva mascara pero la aplico
pui.aplicarMascaraCalibrador(tipoMascara);
- pui.desplegarImagenAR(mostrarDebugAR)
-
+# pui.desplegarImagenAR(mostrarDebugAR)
+ if not dataImagen == None:
+ desplegarDataImage(dataImagen.data)
print '15'
pui.capNext()
- time.sleep(0.09) #FIXME dormir segun el fps
-# print pui.getFPS()
- #Si no pongo el capnext dsps del sleep a veces pisa la imagen
def main():
- global pui
- global aplicar_mascara
- global aplicar_nueva_mascara
- global tomar_muestra
- global muestra
- global cantidad_muestras
- global jugar
- global factorProporcionMaximoH
- global porcentajeMinimoRuido
- global running
+ global pui, aplicar_mascara,aplicar_nueva_mascara,tomar_muestra,muestra,cantidad_muestras,jugar,factorProporcionMaximoH,porcentajeMinimoRuido,running
aplicar_mascara=1
aplicar_nueva_mascara=1
@@ -170,10 +160,10 @@ def main():
initRangosColor()
pui.getModuleInfo()
print '1\n'
- pui.initARConVideo(config_nameCalibrador,"../bin/Data/camera_para.dat",vconf,usarAlgoritmoRapido,1.0)
+ pui.initARConVideo(config_nameCalibrador,"../bin/Data/camera_para.dat",vconf,usarAlgoritmoRapido,pui.NORMAL_SPEED_LOOP,1.0)
print '2\n'
pui.abrirVentanaGrafica()
- time.sleep(1)
+
pui.capStart()
pui.initPropiedadesCalibracionSoloApuntador(PuiModule.FORMA_APUNTADOR_CIRCULO,1,360,0,100,0,100,h_bins,s_bins,v_bins,1)
print '3\n'
diff --git a/Utilidades/src/Pui.cpp b/Utilidades/src/Pui.cpp
index 58d2460..782c028 100644
--- a/Utilidades/src/Pui.cpp
+++ b/Utilidades/src/Pui.cpp
@@ -1493,6 +1493,7 @@ void Pui::setARThreshold(int threshold){
}
void Pui::finish(){
+ capStop();
//cleanupAR();
}
@@ -1508,6 +1509,10 @@ RangosColorApuntador Pui::getResultadosRangosColor(){
return this->propiedades.resultado_rangos_color;
}
+/**
+ * Con la implementacion actual de video.c que trae artoolkit,
+ * esta operacion NO HACE NADA, siempre retorna TRUE
+ */
void Pui::capNext(){
arVideoCapNext();
}
diff --git a/Utilidades/src/Pui.i b/Utilidades/src/Pui.i
index 0c5c41f..860eb3a 100644
--- a/Utilidades/src/Pui.i
+++ b/Utilidades/src/Pui.i
@@ -86,6 +86,12 @@
class Pui {
public:
+
+ static int const FAST_SPEED_LOOP = 15;
+ static int const NORMAL_SPEED_LOOP = 16;
+ static double const FAST_SPEED_LOOP_MULTIPLIER = 1./8.;
+ static double const NORMAL_SPEED_LOOP_MULTIPLIER = 1./2.;
+
int insert(unsigned char *bytes, int len);
binary_data out();
Pui();
@@ -150,7 +156,7 @@ public:
/*Inicializacion de artoolkit
* Si se quiere leer un archivo de configuracion para multi pattern entonces config_name debe contener la ruta del archivo, sino debe ser NULL
* */
- void initARConVideo(char * config_name,char * camera_para,char *vconf,int usarAlgoritmoRapido,double zoom);
+ void initARConVideo(char * config_name,char * camera_para,char *vconf,int usarAlgoritmoRapido,int loopSpeed,double zoom);
int getARThreshold();
diff --git a/Utilidades/src/PuiModule.py b/Utilidades/src/PuiModule.py
index 5457f07..ab5ca22 100644
--- a/Utilidades/src/PuiModule.py
+++ b/Utilidades/src/PuiModule.py
@@ -242,6 +242,10 @@ class Pui(_object):
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Pui, name)
__repr__ = _swig_repr
+ FAST_SPEED_LOOP = _PuiModule.Pui_FAST_SPEED_LOOP
+ NORMAL_SPEED_LOOP = _PuiModule.Pui_NORMAL_SPEED_LOOP
+ FAST_SPEED_LOOP_MULTIPLIER = _PuiModule.Pui_FAST_SPEED_LOOP_MULTIPLIER
+ NORMAL_SPEED_LOOP_MULTIPLIER = _PuiModule.Pui_NORMAL_SPEED_LOOP_MULTIPLIER
def insert(*args): return _PuiModule.Pui_insert(*args)
def out(*args): return _PuiModule.Pui_out(*args)
def __init__(self, *args):
diff --git a/Utilidades/src/PuiModule.pyc b/Utilidades/src/PuiModule.pyc
index 1e0f134..faadb1c 100644
--- a/Utilidades/src/PuiModule.pyc
+++ b/Utilidades/src/PuiModule.pyc
Binary files differ
diff --git a/Utilidades/src/Pui_wrap.cxx b/Utilidades/src/Pui_wrap.cxx
index 7c95a6d..a35de7b 100644
--- a/Utilidades/src/Pui_wrap.cxx
+++ b/Utilidades/src/Pui_wrap.cxx
@@ -2962,6 +2962,12 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
class Pui {
public:
+
+ static int const FAST_SPEED_LOOP = 15;
+ static int const NORMAL_SPEED_LOOP = 16;
+ static double const FAST_SPEED_LOOP_MULTIPLIER = 1./8.;
+ static double const NORMAL_SPEED_LOOP_MULTIPLIER = 1./2.;
+
int insert(unsigned char *bytes, int len);
binary_data out();
Pui();
@@ -3026,7 +3032,7 @@ public:
/*Inicializacion de artoolkit
* Si se quiere leer un archivo de configuracion para multi pattern entonces config_name debe contener la ruta del archivo, sino debe ser NULL
* */
- void initARConVideo(char * config_name,char * camera_para,char *vconf,int usarAlgoritmoRapido,double zoom);
+ void initARConVideo(char * config_name,char * camera_para,char *vconf,int usarAlgoritmoRapido,int loopSpeed,double zoom);
int getARThreshold();
@@ -5866,7 +5872,8 @@ SWIGINTERN PyObject *_wrap_Pui_initARConVideo(PyObject *SWIGUNUSEDPARM(self), Py
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
int arg5 ;
- double arg6 ;
+ int arg6 ;
+ double arg7 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
@@ -5880,16 +5887,19 @@ SWIGINTERN PyObject *_wrap_Pui_initARConVideo(PyObject *SWIGUNUSEDPARM(self), Py
int alloc4 = 0 ;
int val5 ;
int ecode5 = 0 ;
- double val6 ;
+ int val6 ;
int ecode6 = 0 ;
+ double val7 ;
+ int ecode7 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
PyObject * obj4 = 0 ;
PyObject * obj5 = 0 ;
+ PyObject * obj6 = 0 ;
- if (!PyArg_ParseTuple(args,(char *)"OOOOOO:Pui_initARConVideo",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5)) SWIG_fail;
+ if (!PyArg_ParseTuple(args,(char *)"OOOOOOO:Pui_initARConVideo",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Pui, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Pui_initARConVideo" "', argument " "1"" of type '" "Pui *""'");
@@ -5915,12 +5925,17 @@ SWIGINTERN PyObject *_wrap_Pui_initARConVideo(PyObject *SWIGUNUSEDPARM(self), Py
SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "Pui_initARConVideo" "', argument " "5"" of type '" "int""'");
}
arg5 = static_cast< int >(val5);
- ecode6 = SWIG_AsVal_double(obj5, &val6);
+ ecode6 = SWIG_AsVal_int(obj5, &val6);
if (!SWIG_IsOK(ecode6)) {
- SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "Pui_initARConVideo" "', argument " "6"" of type '" "double""'");
+ SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "Pui_initARConVideo" "', argument " "6"" of type '" "int""'");
+ }
+ arg6 = static_cast< int >(val6);
+ ecode7 = SWIG_AsVal_double(obj6, &val7);
+ if (!SWIG_IsOK(ecode7)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "Pui_initARConVideo" "', argument " "7"" of type '" "double""'");
}
- arg6 = static_cast< double >(val6);
- (arg1)->initARConVideo(arg2,arg3,arg4,arg5,arg6);
+ arg7 = static_cast< double >(val7);
+ (arg1)->initARConVideo(arg2,arg3,arg4,arg5,arg6,arg7);
resultobj = SWIG_Py_Void();
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
@@ -6995,5 +7010,9 @@ SWIGEXPORT void SWIG_init(void) {
SWIG_Python_SetConstant(d, "TIPO_MASCARA_ATENUANTE",SWIG_From_int(static_cast< int >(12)));
SWIG_Python_SetConstant(d, "ERROR_TOMAR_MUESTRA_FORMA_NO_IMPLEMENTADA",SWIG_From_int(static_cast< int >(13)));
SWIG_Python_SetConstant(d, "ERROR_TOMAR_MUESTRA_OK",SWIG_From_int(static_cast< int >(14)));
+ SWIG_Python_SetConstant(d, "Pui_FAST_SPEED_LOOP",SWIG_From_int(static_cast< int >(Pui::FAST_SPEED_LOOP)));
+ SWIG_Python_SetConstant(d, "Pui_NORMAL_SPEED_LOOP",SWIG_From_int(static_cast< int >(Pui::NORMAL_SPEED_LOOP)));
+ SWIG_Python_SetConstant(d, "Pui_FAST_SPEED_LOOP_MULTIPLIER",SWIG_From_double(static_cast< double >(Pui::FAST_SPEED_LOOP_MULTIPLIER)));
+ SWIG_Python_SetConstant(d, "Pui_NORMAL_SPEED_LOOP_MULTIPLIER",SWIG_From_double(static_cast< double >(Pui::NORMAL_SPEED_LOOP_MULTIPLIER)));
}
diff --git a/Utilidades/src/prueba.py b/Utilidades/src/prueba.py
index 3513d5a..2c5b92e 100644
--- a/Utilidades/src/prueba.py
+++ b/Utilidades/src/prueba.py
@@ -4,68 +4,60 @@ import PuiModule
from opencv import *
from opencv.highgui import *
-vconf = "v4l2src device=/dev/video0 ! video/x-raw-yuv,width=320,height=240,framerate=10/1 ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24 ! identity name=artoolkit ! fakesink"
-count = 0
+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"
config_nameCalibrador = "../bin/Data/multi/marker.dat"
usarAlgoritmoRapido = 1
-mostrarDebugAR = 0
-aplicarMascara = 0
frameSize = (320,240)
-#FIXME hay que seleccionar los marcadores de manera no secuencial y que no se repitan. Por el momento comienza en 0 y se va incrementando de a 1
-id_marcador =0
-tipoMascara = PuiModule.TIPO_MASCARA_BINARIA
-err_deteccion = 0
-
-cantidad_muestras= 6
-res_aplicar_mascara = 0
-muestra = 0
-
-aplicar_mascara=1
-aplicar_nueva_mascara=1
-tomar_muestra=0
-thresh = 100
-factorProporcionMaximoH = 10
-porcentajeMinimoRuido = 7
-
-
running = True
+displayPyGame = False
+displaySDL = False
+
+count =0
-def main():
+def main():
+ global frameSize, usarAlgoritmoRapido,config_nameCalibrador,vconf,displayPyGame,displaySDL,count
+ size = (320,240)
pui = PuiModule.Pui()
pui.getModuleInfo()
print '1\n'
- pui.initARConVideo(config_nameCalibrador,"../bin/Data/camera_para.dat",vconf,usarAlgoritmoRapido,1.0)
+ pui.initARConVideo(config_nameCalibrador,"../bin/Data/camera_para.dat",vconf,usarAlgoritmoRapido,pui.NORMAL_SPEED_LOOP,1.0)
pui.setDebugCalibracion(False)
print '4\n'
- #pui.abrirVentanaGrafica()
+ if displaySDL:
+ print '---- Desplegaremos en SDL manejado por PuiModule ----'
+ pui.abrirVentanaGrafica()
+ elif displayPyGame:
+ screen = pygame.display.set_mode(size)
+ surface = pygame.display.get_surface()
pui.capStart()
print '5\n'
running = True
- size = (320,240)
- print '5.1\n'
- screen = pygame.display.set_mode(size)
- print '5.2\n'
- surface = pygame.display.get_surface()
- print '6\n'
-
-
while running:
array = pui.capturarPyImageAR()
- if not array == None:
-# print 'NO array es none!'
- pg_img = pygame.image.frombuffer(array.data,size, "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
- #else:
- # print 'array es none!'
-
-
+ if displaySDL:
+ pui.desplegarImagenAR(False)
+ count=count +1
+ if count >=1000:
+ running=False
+ elif displayPyGame:
+ if not array == None:
+ pg_img = pygame.image.frombuffer(array.data,size, "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
+ else:
+ count=count +1
+ if count >=1000:
+ running=False
+ print '************'
+ print pui.getFPS()
+ print '(frame/sec)\n'
+
if __name__ == "__main__":
main()