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
00018
00019
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 *patt_name = "Data/patt.hiro";
00035 int patt_id;
00036 double patt_width = 80.0;
00037 double patt_center[2] = {0.0, 0.0};
00038 double patt_trans[3][4];
00039
00040 static void init(void);
00041 static void cleanup(void);
00042 static void keyEvent( unsigned char key, int x, int y);
00043 static void mainLoop(void);
00044 static void draw( void );
00045
00046 int main(int argc, char **argv)
00047 {
00048 glutInit(&argc, argv);
00049 init();
00050
00051 arVideoCapStart();
00052 argMainLoop( NULL, keyEvent, mainLoop );
00053 return (0);
00054 }
00055
00056 static void keyEvent( unsigned char key, int x, int y)
00057 {
00058
00059 if( key == 0x1b ) {
00060 printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
00061 cleanup();
00062 exit(0);
00063 }
00064 }
00065
00066
00067 static void mainLoop(void)
00068 {
00069 ARUint8 *dataPtr;
00070 ARMarkerInfo *marker_info;
00071 int marker_num;
00072 int j, k;
00073
00074
00075 if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
00076 arUtilSleep(2);
00077 return;
00078 }
00079 if( count == 0 ) arUtilTimerReset();
00080 count++;
00081
00082 argDrawMode2D();
00083 argDispImage( dataPtr, 0,0 );
00084
00085
00086 if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
00087 cleanup();
00088 exit(0);
00089 }
00090
00091 arVideoCapNext();
00092
00093
00094 k = -1;
00095 for( j = 0; j < marker_num; j++ ) {
00096 if( patt_id == marker_info[j].id ) {
00097 if( k == -1 ) k = j;
00098 else if( marker_info[k].cf < marker_info[j].cf ) k = j;
00099 }
00100 }
00101 if( k == -1 ) {
00102 argSwapBuffers();
00103 return;
00104 }
00105
00106
00107 arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
00108
00109 draw();
00110
00111 argSwapBuffers();
00112 }
00113
00114 static void init( void )
00115 {
00116 ARParam wparam;
00117
00118
00119 if( arVideoOpen( vconf ) < 0 ) exit(0);
00120
00121 if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
00122 printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
00123
00124
00125 if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
00126 printf("Camera parameter load error !!\n");
00127 exit(0);
00128 }
00129 arParamChangeSize( &wparam, xsize, ysize, &cparam );
00130 arInitCparam( &cparam );
00131 printf("*** Camera Parameter ***\n");
00132 arParamDisp( &cparam );
00133
00134 if( (patt_id=arLoadPatt(patt_name)) < 0 ) {
00135 printf("pattern load error !!\n");
00136 exit(0);
00137 }
00138
00139
00140 argInit( &cparam, 1.0, 0, 0, 0, 0 );
00141 }
00142
00143
00144 static void cleanup(void)
00145 {
00146 arVideoCapStop();
00147 arVideoClose();
00148 argCleanup();
00149 }
00150
00151 static void draw( void )
00152 {
00153 double gl_para[16];
00154 GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0};
00155 GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0};
00156 GLfloat mat_flash_shiny[] = {50.0};
00157 GLfloat light_position[] = {100.0,-200.0,200.0,0.0};
00158 GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
00159 GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};
00160
00161 argDrawMode3D();
00162 argDraw3dCamera( 0, 0 );
00163 glClearDepth( 1.0 );
00164 glClear(GL_DEPTH_BUFFER_BIT);
00165 glEnable(GL_DEPTH_TEST);
00166 glDepthFunc(GL_LEQUAL);
00167
00168
00169 argConvGlpara(patt_trans, gl_para);
00170 glMatrixMode(GL_MODELVIEW);
00171 glLoadMatrixd( gl_para );
00172
00173 glEnable(GL_LIGHTING);
00174 glEnable(GL_LIGHT0);
00175 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00176 glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
00177 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
00178 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
00179 glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
00180 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00181 glMatrixMode(GL_MODELVIEW);
00182 glTranslatef( 0.0, 0.0, 25.0 );
00183 glutSolidCube(50.0);
00184 glDisable( GL_LIGHTING );
00185
00186 glDisable( GL_DEPTH_TEST );
00187 }