Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/multi/SRC/clicks.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'multi/SRC/clicks.cpp')
-rw-r--r--multi/SRC/clicks.cpp542
1 files changed, 0 insertions, 542 deletions
diff --git a/multi/SRC/clicks.cpp b/multi/SRC/clicks.cpp
deleted file mode 100644
index 6df13ee..0000000
--- a/multi/SRC/clicks.cpp
+++ /dev/null
@@ -1,542 +0,0 @@
-#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 "stdio.h"
-#include "stdlib.h"
-#include "detectorCuadrados.cpp"
-#include <unistd.h>
-#include <math.h>
-#include <formatopixel.h>
-
-#include "cvUtilities.h"
-
-#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 UMBRAL 5
-#define MAX_APUNTADORES 6
-
-/* 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;
-
-int gris = 0;
-char *cparam_name = "Data/camera_para.dat";
-ARParam cparam;
-
-char *config_name = "Data/multi/marker.dat";
-ARMultiMarkerInfoT *config;
-double patt_trans[3][4];
-
-int umbral = UMBRAL;
-int minH = MIN_H, maxH = MAX_H, minS = MIN_S, maxS = MAX_S, minB = MIN_B,maxB = MAX_B;
-int invert = 0;
-int num_apuntadores =0;
-
-IplImage* img =NULL;
-IplImage* hsv_image = NULL;
-uchar* data1 =NULL;
-
-
-
-
-/*La posicion i del arreglo corresponde al marcador con con patt_id=i*/
-ARCoordMarcador marcadoresOcultos[10]; //TODO ver que tamano asignar a este arreglo
-
-CoordApuntador apuntadores[MAX_APUNTADORES*2];
-
-
-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("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 == '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;
- }
-
-
-}
-
-
-
-
-static void detectarElementoPorSegmentacion(IplImage* img ){
- img->origin = IPL_ORIGIN_TL;
-
- IplImage* mono_Image = cvCreateImage( cvGetSize(img), 8, 1 );
- segmentarImagen(img,mono_Image,hlower,hupper,0);
- if(hayRectangulo(mono_Image,MIN_AREA)){
- // printf("******************* ENCONTRO RECTANGULOOOOOOOOOOO *******************\n");
- }
-}
-
-void detectarDedalOpenCv(ARUint8 *dataPtr){
- IplImage* imagenCv = crearImagenCv(dataPtr,xsize,ysize);
- detectarElementoPorSegmentacion(imagenCv);
-}
-
-void convertirRGB2HSV(ARUint8 *dataPtr){
- if(img==NULL){
- img = crearImagenCv(dataPtr,xsize,ysize); // Si probamos con tamanos mas chicos consume mucho menos!!
- }
- if(hsv_image==NULL){
- hsv_image = cvCreateImage( cvGetSize(img), 8, 3 );
- }
- cvCvtColor(img,hsv_image,CV_RGB2HSV);
-}
-
-
-/**
- * busca el dedal en toda la imagen
- * */
-void detectarDedal2(ARUint8 *dataPtr){
- int label_num;
- int *area;
- double *pos;
- int *label_ref;
- ARMarkerInfo2 *marker2;
- ARInt16 *limage;
- int *clip;
- int i,j;
-
-
- if(img==NULL){
- printf("---------------->CREO LA IMAGEN OPENCV PORQUE ERA NULL 111\n\n\n");
- img = crearImagenCv2(dataPtr,xsize,ysize);
- }
- if(data1==NULL){
- data1= new uchar[img->width* img->nChannels *img->height];
- }
- memcpy(data1,(uchar*)dataPtr,img->width* img->nChannels*img->height );
-
- cvSetImageData( img, data1, img->width* img->nChannels );
-
- int heightBak = img->height;
- if(arImageProcMode == AR_IMAGE_PROC_IN_HALF ){
- //Debemos convertir solo linea por medio
- img->widthStep *= 2;
- img->height = cvFloor(img->height/2); //por las dudas de que el alto sea impar, es muy improbable q pase
- //Debemos convertir un pixel si y uno no
- //img->nChannels *= 2;
- }
-
- //cvNamedWindow("prueba");
- //cvShowImage("prueba",img);
- //cvWaitKey(0);
- //cvDestroyAllWindows();
-// cvSetImageROI(img,cvRect(10,10,400,400));
-
- if(arImageProcMode == AR_IMAGE_PROC_IN_HALF ){
- img->widthStep /= 2;
- img->height = heightBak;
- //img->nChannels /= 2;
- }
-
- limage = arLabelingHSB2( (ARUint8*)img->imageData, thresh, &label_num, &area, &pos, &clip, &label_ref, 1, minH, maxH, minS, maxS, minB,maxB, invert);
- if( limage == 0 ) {
- printf("CAYENDO POR arLabelingHSB\n");
- cleanup();
- exit(0);
- }
-
- marker2 = arDetectMarker3( limage, label_num, label_ref,area, pos, clip, AR_AREA_MAX, AR_AREA_MIN, &num_apuntadores);
- if( marker2 == 0 ) {
- printf("CAYENDO POR arDetectMarker3\n");
- cleanup();
- exit(0);
- }
-
-// printf("Numero de marcadores detectados por arDetectMarker3=%d\n",num_apuntadores);
- if(num_apuntadores > MAX_APUNTADORES){ //Me estoy perdiendo de algunos apuntadores detectados
- // printf("////**** CUIDADO, SE ESTAN DETECTANDO DEMASIADOS APUNTADORES Y SE ESTAN DESCARTARNDO %d DE ELLOS ****\n",num_apuntadores);
- num_apuntadores = MAX_APUNTADORES;
- }
- /*if(num_apuntadores==0){
- printf("NO SE DETECTARON APUNTADORES \n");
- }else{*/
- argDrawMode2D();
- glLineWidth(6.0);
- glColor3f( 0.0, 0.0, 1.0 );
- for( i = 0; i < num_apuntadores; i++ ) {
- //dibujo el centro y los vertices
- /*for(j=0; j<marker2[i].coord_num-1; j++) {
- argLineSeg( marker2[i].x_coord[j] , marker2[i].y_coord[j], marker2[i].x_coord
- [j+1], marker2[i].y_coord[j+1], 0, 0);
- }*/
-
- //seteo info del marcador
- apuntadores[i].area = marker2[i].area;
- apuntadores[i].centro[0] = marker2[i].pos[0];
- apuntadores[i].centro[1] = marker2[i].pos[1];
- }
- //}
-}
-
-/**
- * busca el dedal en toda la imagen
- * */
-void detectarDedalLocal(ARUint8 *dataPtr){
- int label_num;
- int *area;
- double *pos;
- int *label_ref;
- ARMarkerInfo2 *marker2;
- ARInt16 *limage;
- int *clip;
- int i,j;
-
-
- limage = arLabelingHSB( dataPtr, &label_num, &area, &pos, &clip, &label_ref, 1, minH, maxH, minS, maxS, minB,maxB, invert);
- if( limage == 0 ) {
- printf("CAYENDO POR arLabelingHSB\n");
- cleanup();
- exit(0);
- }
-
- marker2 = arDetectMarker3( limage, label_num, label_ref,area, pos, clip, AR_AREA_MAX, AR_AREA_MIN, &num_apuntadores);
- if( marker2 == 0 ) {
- printf("CAYENDO POR arDetectMarker3\n");
- cleanup();
- exit(0);
- }
-
-// printf("Numero de marcadores detectados por arDetectMarker3=%d\n",num_apuntadores);
- if(num_apuntadores > MAX_APUNTADORES){ //Me estoy perdiendo de algunos apuntadores detectados
- // printf("////**** CUIDADO, SE ESTAN DETECTANDO DEMASIADOS APUNTADORES Y SE ESTAN DESCARTARNDO %d DE ELLOS ****\n",num_apuntadores);
- num_apuntadores = MAX_APUNTADORES;
- }
- /*if(num_apuntadores==0){
- printf("NO SE DETECTARON APUNTADORES \n");
- }else{*/
- argDrawMode2D();
- glLineWidth(6.0);
- glColor3f( 0.0, 0.0, 1.0 );
- for( i = 0; i < num_apuntadores; i++ ) {
- //dibujo el centro y los vertices
- /*for(j=0; j<marker2[i].coord_num-1; j++) {
- argLineSeg( marker2[i].x_coord[j] , marker2[i].y_coord[j], marker2[i].x_coord
- [j+1], marker2[i].y_coord[j+1], 0, 0);
- }*/
-
- //seteo info del marcador
- apuntadores[i].area = marker2[i].area;
- apuntadores[i].centro[0] = marker2[i].pos[0];
- apuntadores[i].centro[1] = marker2[i].pos[1];
- }
- //}
-}
-
-/**
- * Recibe el indice del marcador no detectado y chequea si algun apuntador esta colisionando con el mismo.
- * Devuelve el indice del apuntador si hay colision, -1 en caso contrario
- */
-int hayColision(int indiceMarcdor){
-
- double a_cuadrado,b_cuadrado, radioMarcador;
- double centro_x = marcadoresOcultos[indiceMarcdor].centro[0];
- double centro_y = marcadoresOcultos[indiceMarcdor].centro[1];
-
- a_cuadrado = pow(centro_x - marcadoresOcultos[indiceMarcdor].vertex[0][0],2); // (Centro.X - v0.X)^2
- b_cuadrado = pow( marcadoresOcultos[indiceMarcdor].vertex[0][1] - centro_y,2 ); // (v0.y - Centro.Y)^2
- radioMarcador = sqrt(a_cuadrado + b_cuadrado);
- int i;
- for(i=0;i<num_apuntadores;i++){
- double a1_cuadrado = pow( abs(apuntadores[i].centro[0] - centro_x),2 );
- double b1_cuadrado = pow( abs(apuntadores[i].centro[1] - centro_y),2 );
- double d = sqrt(a1_cuadrado + b1_cuadrado);
- if(d<radioMarcador){
- return i;
- }
- }
- return -1;
-}
-
-/* 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);
- }
- //cvSetImageData( img, dataPtr, img->width* img->nChannels );
-
- /* detect the markers in the video frame */
- if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
- cleanup();
- exit(0);
- }
-
- //detectarDedal2(dataPtr);
- //detectarDedalLocal(dataPtr);
- num_apuntadores = detectarApuntador(dataPtr,0,minH,maxH,minS,maxS,minB,maxB,150,AR_AREA_MAX,10,apuntadores);
-
-
- //cvCvtColor(img,img,CV_RGB2HSV);
-
- /*double H,S,V;
-
- ARUint8* pnt = dataPtr;
- for( int y=0; y<ysize; y++ ) {
- for( int x=0; x<img->width; x++,pnt++ ) {
- RGBtoHSV(R_COMP,G_COMP,B_COMP,&H,&S,&V);
-
- }
- }*/
-
- //detectarDedalOpenCv(dataPtr);
- //convertirRGB2HSV(dataPtr);
- //cvCvtColor(img, img, CV_RGB2HSV);
- 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 );
- }
-
- arVideoCapNext();
-
- if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
- argSwapBuffers();
- return;
- }
-
- if(err > 100.0 ) {
- printf("saliendo 2\n");
- argSwapBuffers();
- return;
- }
-
- 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( 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];
- }
-
- dibujarPuntosMarcadorNoDetectado(Xi,Yi,marcadoresOcultos[i].vertex);
-
- int apuntadorCol = hayColision(i);
- if(apuntadorCol>=0){ //Chequea que algun apuntado este colisionando con el marcador i
- printf("&&&&&&&&&&& COLISION ENTRE APUNTADOR %d Y MARCADOR %d &&&&&&&&&&&&&&&",apuntadorCol,i);
- printf("\n&&&&&&&&&&& AREA = %d &&&&&&&&&&&&&&&",apuntadores[apuntadorCol].area,i);
-
- break; // Por ahora cuando se detecta la primera colision ya frenamos
- }
-
- }
-
- }
- }
-
-
- /* TODO SI PUDE CONSEGUIR LA INFORMACION 3D DEL MARCADOR DETECTADO POR COLOR ENTONCES LA MATRIZ DE TRANSFORMACION
- DEBERIA OBTENERLA SIN PROBLEMAS
- if( (err=arGetTransMat(marker_info,centroApuntador,anchoApuntador,patt_trans)) < 0 ) {
- printf("return en el mainloop luego de obtener transformacion \n");
- argSwapBuffers();
- return;
- }else{
- printf("****************TRANSFORMACION EXITOSA****************** \n");
- }
- */
-
- //printf("err = %f\n", err);
-
- argSwapBuffers();
-
-}
-
-
-static void init( void )
-{
- ARParam wparam;
- //Cargo configuracion del color a detectar
- cargarDeFichero();
- /* 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 );
-
- 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_IDEAL;
- arImageProcMode = AR_IMAGE_PROC_IN_HALF;
- argDrawMode = AR_DRAW_BY_TEXTURE_MAPPING;
- argTexmapMode = AR_DRAW_TEXTURE_HALF_IMAGE;
-
-}
-
-/* cleanup function called when program exits */
-static void cleanup(void)
-{
- arVideoCapStop();
- arVideoClose();
- argCleanup();
-}