Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tags/Version inicial desplegando imagen en pantalla
diff options
context:
space:
mode:
Diffstat (limited to 'tags/Version inicial desplegando imagen en pantalla')
-rw-r--r--tags/Version inicial desplegando imagen en pantalla427
1 files changed, 0 insertions, 427 deletions
diff --git a/tags/Version inicial desplegando imagen en pantalla b/tags/Version inicial desplegando imagen en pantalla
deleted file mode 100644
index 2332613..0000000
--- a/tags/Version inicial desplegando imagen en pantalla
+++ /dev/null
@@ -1,427 +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 <opencv/cvwimage.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;
-cvUtilities* util;
-
-typedef struct {
- int area;
- double centro[2];
- double vertex[4][2];
-} CoordMarcadorNoDetectado;
-
-typedef struct {
- int area;
- double centro[2];
-} CoordApuntador;
-
-/*La posicion i del arreglo corresponde al marcador con con patt_id=i*/
-CoordMarcadorNoDetectado marcadoresOcultos[10]; //TODO ver que tamano asignar a este arreglo
-
-CoordApuntador apuntadores[MAX_APUNTADORES];
-
-
-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,"%d",&umbral);
- 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;
- }
-
-
-}
-
-
-
-/**
- * busca el dedal en toda la imagen
- * */
-void detectarDedal(ARUint8 *dataPtr){
- int label_num;
- int *area;
- double *pos;
- int *label_ref;
- ARMarkerInfo2 *marker2;
- ARInt16 *limage;
- int *clip;
- int i,j;
-
-
- limage = arLabelingHSB( dataPtr, 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();
- int j;
- 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];
- }
- }
-}
-
-
-
-void dibujarPuntosMarcadorNoDetectado(double Xi, double Yi,double vertex[4][2]){
- argDrawMode2D();
- //Dibujo el centro
- glColor3f( 1.0, 0.0, 0.0 );
- glLineWidth(5.0);
- argLineSeg( Xi , Yi, Xi + 20, Yi, 0, 0);
-
- //Dibujo los vertices
- glColor3f( 0.0, 1.0, 0.0 );
- int vertice;
- for(vertice=0;vertice<4;vertice++){
- argLineSeg( vertex[vertice][0] , vertex[vertice][1], vertex[vertice][0] + 20, vertex[vertice][1], 0, 0);
- }
-}
-
-
-/**
- * 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++;
-
-
- /* detect the markers in the video frame */
- if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
- cleanup();
- exit(0);
- }
-
- detectarDedal(dataPtr);
-
- 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 CON MARCADOR %D &&&&&&&&&&&&&&&",apuntadorCol);
- 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();
-}