multiTest.c
Go to the documentation of this file.
00001 #ifdef _WIN32
00002 #include <windows.h>
00003 #endif
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #ifndef __APPLE__
00007 #include <GL/gl.h>
00008 #include <GL/glut.h>
00009 #else
00010 #include <OpenGL/gl.h>
00011 #include <GLUT/glut.h>
00012 #endif
00013 #include <AR/gsub.h>
00014 #include <AR/video.h>
00015 #include <AR/param.h>
00016 #include <AR/ar.h>
00017 #include <AR/arMulti.h>
00018 
00019 /* set up the video format globals */
00020 
00021 #ifdef _WIN32
00022 char                    *vconf = "Data\\WDM_camera_flipV.xml";
00023 #else
00024 char                    *vconf = "";
00025 #endif
00026 
00027 int             xsize, ysize;
00028 int             thresh = 100;
00029 int             count = 0;
00030 
00031 char           *cparam_name    = "Data/camera_para.dat";
00032 ARParam         cparam;
00033 
00034 char                *config_name = "Data/multi/marker.dat";
00035 ARMultiMarkerInfoT  *config;
00036 
00037 static void   init(void);
00038 static void   cleanup(void);
00039 static void   keyEvent( unsigned char key, int x, int y);
00040 static void   mainLoop(void);
00041 static void   draw( double trans1[3][4], double trans2[3][4], int mode );
00042 
00043 
00044 int main(int argc, char **argv)
00045 {
00046         glutInit(&argc, argv);
00047     init();
00048 
00049     arVideoCapStart();
00050     argMainLoop( NULL, keyEvent, mainLoop );
00051         return (0);
00052 }
00053 
00054 static void   keyEvent( unsigned char key, int x, int y)
00055 {
00056     /* quit if the ESC key is pressed */
00057     if( key == 0x1b ) {
00058         printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
00059         cleanup();
00060         exit(0);
00061     }
00062 
00063     if( key == 't' ) {
00064         printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
00065         printf("Enter new threshold value (current = %d): ", thresh);
00066         scanf("%d",&thresh); while( getchar()!='\n' );
00067         printf("\n");
00068         count = 0;
00069     }
00070 
00071     /* turn on and off the debug mode with right mouse */
00072     if( key == 'd' ) {
00073         printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
00074         arDebug = 1 - arDebug;
00075         if( arDebug == 0 ) {
00076             glClearColor( 0.0, 0.0, 0.0, 0.0 );
00077             glClear(GL_COLOR_BUFFER_BIT);
00078             argSwapBuffers();
00079             glClear(GL_COLOR_BUFFER_BIT);
00080             argSwapBuffers();
00081         }
00082         count = 0;
00083     }
00084 
00085 }
00086 
00087 /* main loop */
00088 static void mainLoop(void)
00089 {
00090     ARUint8         *dataPtr;
00091     ARMarkerInfo    *marker_info;
00092     int             marker_num;
00093     double          err;
00094     int             i;
00095 
00096     /* grab a vide frame */
00097     if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
00098         arUtilSleep(2);
00099         return;
00100     }
00101     if( count == 0 ) arUtilTimerReset();
00102     count++;
00103 
00104     /* detect the markers in the video frame */
00105     if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
00106         cleanup();
00107         exit(0);
00108     }
00109 
00110     argDrawMode2D();
00111     if( !arDebug ) {
00112         argDispImage( dataPtr, 0,0 );
00113     }
00114     else {
00115         argDispImage( dataPtr, 1, 1 );
00116         if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
00117             argDispHalfImage( arImage, 0, 0 );
00118         else
00119             argDispImage( arImage, 0, 0);
00120 
00121         glColor3f( 1.0, 0.0, 0.0 );
00122         glLineWidth( 1.0 );
00123         for( i = 0; i < marker_num; i++ ) {
00124             argDrawSquare( marker_info[i].vertex, 0, 0 );
00125         }
00126         glLineWidth( 1.0 );
00127     }
00128 
00129     arVideoCapNext();
00130 
00131     if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
00132         argSwapBuffers();
00133         return;
00134     }
00135     printf("err = %f\n", err);
00136     if(err > 100.0 ) {
00137         argSwapBuffers();
00138         return;
00139     }
00140 /*
00141     for(i=0;i<3;i++) {
00142         for(j=0;j<4;j++) printf("%10.5f ", config->trans[i][j]);
00143         printf("\n");
00144     }
00145     printf("\n");
00146 */
00147     argDrawMode3D();
00148     argDraw3dCamera( 0, 0 );
00149     glClearDepth( 1.0 );
00150     glClear(GL_DEPTH_BUFFER_BIT);
00151     for( i = 0; i < config->marker_num; i++ ) {
00152         if( config->marker[i].visible >= 0 ) draw( config->trans, config->marker[i].trans, 0 );
00153         else                                 draw( config->trans, config->marker[i].trans, 1 );
00154     }
00155     argSwapBuffers();
00156 }
00157 
00158 static void init( void )
00159 {
00160     ARParam  wparam;
00161 
00162     /* open the video path */
00163     if( arVideoOpen( vconf ) < 0 ) exit(0);
00164     /* find the size of the window */
00165     if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
00166     printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
00167 
00168     /* set the initial camera parameters */
00169     if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
00170         printf("Camera parameter load error !!\n");
00171         exit(0);
00172     }
00173     arParamChangeSize( &wparam, xsize, ysize, &cparam );
00174     arInitCparam( &cparam );
00175     printf("*** Camera Parameter ***\n");
00176     arParamDisp( &cparam );
00177 
00178     if( (config = arMultiReadConfigFile(config_name)) == NULL ) {
00179         printf("config data load error !!\n");
00180         exit(0);
00181     }
00182 
00183     /* open the graphics window */
00184     argInit( &cparam, 1.0, 0, 2, 1, 0 );
00185     arFittingMode   = AR_FITTING_TO_IDEAL;
00186     arImageProcMode = AR_IMAGE_PROC_IN_HALF;
00187     argDrawMode     = AR_DRAW_BY_TEXTURE_MAPPING;
00188     argTexmapMode   = AR_DRAW_TEXTURE_HALF_IMAGE;
00189 }
00190 
00191 /* cleanup function called when program exits */
00192 static void cleanup(void)
00193 {
00194     arVideoCapStop();
00195     arVideoClose();
00196     argCleanup();
00197 }
00198 
00199 static void draw( double trans1[3][4], double trans2[3][4], int mode )
00200 {
00201     double    gl_para[16];
00202     GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
00203     GLfloat   mat_ambient1[]    = {1.0, 0.0, 0.0, 1.0};
00204     GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
00205     GLfloat   mat_flash1[]      = {1.0, 0.0, 0.0, 1.0};
00206     GLfloat   mat_flash_shiny[] = {50.0};
00207     GLfloat   mat_flash_shiny1[]= {50.0};
00208     GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
00209     GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
00210     GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
00211     
00212     argDrawMode3D();
00213     argDraw3dCamera( 0, 0 );
00214     glEnable(GL_DEPTH_TEST);
00215     glDepthFunc(GL_LEQUAL);
00216     
00217     /* load the camera transformation matrix */
00218     glMatrixMode(GL_MODELVIEW);
00219     argConvGlpara(trans1, gl_para);
00220     glLoadMatrixd( gl_para );
00221     argConvGlpara(trans2, gl_para);
00222     glMultMatrixd( gl_para );
00223 
00224     if( mode == 0 ) {
00225         glEnable(GL_LIGHTING);
00226         glEnable(GL_LIGHT0);
00227         glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00228         glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
00229         glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
00230         glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
00231         glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);  
00232         glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00233     }
00234     else {
00235         glEnable(GL_LIGHTING);
00236         glEnable(GL_LIGHT0);
00237         glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00238         glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
00239         glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
00240         glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash1);
00241         glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1); 
00242         glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient1);
00243     }
00244     glMatrixMode(GL_MODELVIEW);
00245     glTranslatef( 0.0, 0.0, 25.0 );
00246     if( !arDebug ) glutSolidCube(50.0);
00247      else          glutWireCube(50.0);
00248     glDisable( GL_LIGHTING );
00249 
00250     glDisable( GL_DEPTH_TEST );
00251 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00