[artoolkit-commits] artoolkit/util/calib_camera2 main.c,1.4,1.5
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2005-08-10 18:17:05
|
Update of /cvsroot/artoolkit/artoolkit/util/calib_camera2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14396 Modified Files: main.c Log Message: Step 1 of cleanup. Index: main.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/util/calib_camera2/main.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.c 23 Jul 2005 00:02:32 -0000 1.4 --- main.c 10 Aug 2005 18:16:51 -0000 1.5 *************** *** 20,24 **** #include "calib_camera.h" ! #define USE_TEXMAP #ifndef GL_ABGR --- 20,24 ---- #include "calib_camera.h" ! //#define USE_TEXMAP #ifndef GL_ABGR *************** *** 38,41 **** --- 38,43 ---- #endif + /* set up the video format globals */ + #if defined(__sgi) char *vconf = "-size=FULL"; *************** *** 53,57 **** # endif #elif defined(_WIN32) ! char *vconf = "WDM_camera_flipV.xml"; #elif defined(__APPLE__) char *vconf = "-width=640 -height=480"; --- 55,59 ---- # endif #elif defined(_WIN32) ! char *vconf = "Data\\WDM_camera_flipV.xml"; #elif defined(__APPLE__) char *vconf = "-width=640 -height=480"; *************** *** 59,64 **** char *vconf = ""; #endif - /*****************************************************************************/ int win; --- 61,66 ---- char *vconf = ""; #endif + static ARUint8 *gARTImage = NULL; int win; *************** *** 73,79 **** int point_num; ! int sx, sy, ex, ey; ! int status; int check_num; --- 75,81 ---- int point_num; ! int sx, sy, ex, ey; // x and y coordinates of start and end of mouse drag. ! int gStatus; // 0 = , 1 = , 2 = . int check_num; *************** *** 87,91 **** #endif ! static void init( int argc, char *argv[] ); static void mouseEvent(int button, int state, int x, int y); static void motionEvent( int x, int y ); --- 89,93 ---- #endif ! static int init( int argc, char *argv[] ); static void mouseEvent(int button, int state, int x, int y); static void motionEvent( int x, int y ); *************** *** 127,140 **** { glutInit(&argc, argv); ! init( argc, argv ); glutKeyboardFunc(keyEvent); glutMouseFunc(mouseEvent); glutMotionFunc(motionEvent); ! glutIdleFunc(dispImage); glutDisplayFunc(dispImage); print_comment(0); ! status = 0; point_num = 0; arVideoCapStart(); --- 129,142 ---- { glutInit(&argc, argv); ! if (!init(argc, argv)) exit(-1); glutKeyboardFunc(keyEvent); glutMouseFunc(mouseEvent); glutMotionFunc(motionEvent); ! glutIdleFunc(Idle); glutDisplayFunc(dispImage); print_comment(0); ! gStatus = 0; point_num = 0; arVideoCapStart(); *************** *** 143,147 **** } ! static void init(int argc, char *argv[]) { double length; --- 145,149 ---- } ! static int init(int argc, char *argv[]) { double length; *************** *** 154,158 **** if (patt.h_num < 3 || patt.v_num < 3) exit(0); ! printf("Input the length between each markers: "); scanf("%lf", &length); while (getchar() != '\n'); --- 156,160 ---- if (patt.h_num < 3 || patt.v_num < 3) exit(0); ! printf("Input the distance between each marker dot, in millimeters: "); scanf("%lf", &length); while (getchar() != '\n'); *************** *** 164,168 **** } } ! strcpy(line, vconf); for (i = 1; i < argc; i++) { --- 166,171 ---- } } ! ! // Add command-line arguments to vconf string. strcpy(line, vconf); for (i = 1; i < argc; i++) { *************** *** 170,176 **** strcat(line, argv[i]); } ! if (arVideoOpen(line) < 0) exit(0); ! if (arVideoInqSize(&xsize, &ysize) < 0) exit(0); ! printf("Image size (x,y) = (%d,%d)\n", xsize, ysize); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); --- 173,185 ---- strcat(line, argv[i]); } ! ! // Open the video path. ! if (arVideoOpen(line) < 0) { ! fprintf(stderr, "init(): Unable to open connection to camera.\n"); ! return (FALSE); ! } ! // Find the size of the window. ! if (arVideoInqSize(&xsize, &ysize) < 0) return (FALSE); ! fprintf(stdout, "Camera image size (x,y) = (%d,%d)\n", xsize, ysize); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); *************** *** 224,228 **** int i, j, k; ! if( status == 1 && sx != -1 && sy != -1 ) { ex = x; ey = y; --- 233,237 ---- int i, j, k; ! if( gStatus == 1 && sx != -1 && sy != -1 ) { ex = x; ey = y; *************** *** 293,297 **** if( button == GLUT_RIGHT_BUTTON && state == GLUT_UP ) { ! if( status == 0 ) { arVideoCapStop(); arVideoClose(); --- 302,306 ---- if( button == GLUT_RIGHT_BUTTON && state == GLUT_UP ) { ! if( gStatus == 0 ) { arVideoCapStop(); arVideoClose(); *************** *** 305,309 **** printf("Size Adjust: %f\n", dist_factor[3]); printf("--------------\n"); ! status = 2; check_num = 0; print_comment(5); --- 314,318 ---- printf("Size Adjust: %f\n", dist_factor[3]); printf("--------------\n"); ! gStatus = 2; check_num = 0; print_comment(5); *************** *** 314,323 **** } } ! else if( status == 1 ) { if( patt.loop_num == 0 ) {printf("error!!\n"); exit(0);} patt.loop_num--; free( patt.point[patt.loop_num] ); free( patt.savedImage[patt.loop_num] ); ! status = 0; point_num = 0; arVideoCapStart(); --- 323,332 ---- } } ! else if( gStatus == 1 ) { if( patt.loop_num == 0 ) {printf("error!!\n"); exit(0);} patt.loop_num--; free( patt.point[patt.loop_num] ); free( patt.savedImage[patt.loop_num] ); ! gStatus = 0; point_num = 0; arVideoCapStart(); *************** *** 329,333 **** if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { ! if( status == 1 && point_num < patt.h_num*patt.v_num ) { sx = ex = x; sy = ey = y; --- 338,342 ---- if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { ! if( gStatus == 1 && point_num < patt.h_num*patt.v_num ) { sx = ex = x; sy = ey = y; *************** *** 382,386 **** if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { ! if( status == 0 && patt.loop_num < LOOP_MAX ) { while( (p = (unsigned char *)arVideoGetImage()) == NULL ) { arUtilSleep(2); --- 391,395 ---- if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { ! if( gStatus == 0 && patt.loop_num < LOOP_MAX ) { while( (p = (unsigned char *)arVideoGetImage()) == NULL ) { arUtilSleep(2); *************** *** 401,411 **** patt.loop_num++; ! status = 1; sx = sy = ex= ey = -1; print_comment(1); } ! else if( status == 1 && point_num == patt.h_num*patt.v_num ) { ! status = 0; point_num = 0; arVideoCapStart(); --- 410,420 ---- patt.loop_num++; ! gStatus = 1; sx = sy = ex= ey = -1; print_comment(1); } ! else if( gStatus == 1 && point_num == patt.h_num*patt.v_num ) { ! gStatus = 0; point_num = 0; arVideoCapStart(); *************** *** 423,427 **** else print_comment(6); } ! else if( status == 1 ) { if( sx < ex ) { ssx = sx; eex = ex; } else { ssx = ex; eex = sx; } --- 432,436 ---- else print_comment(6); } ! else if( gStatus == 1 ) { if( sx < ex ) { ssx = sx; eex = ex; } else { ssx = ex; eex = sx; } *************** *** 453,457 **** if( point_num == patt.h_num*patt.v_num ) print_comment(2); } ! else if( status == 2 ) { check_num++; if( check_num == patt.loop_num ) { --- 462,466 ---- if( point_num == patt.h_num*patt.v_num ) print_comment(2); } ! else if( gStatus == 2 ) { check_num++; if( check_num == patt.loop_num ) { *************** *** 492,514 **** } static void dispImage(void) { - unsigned char *dataPtr; double x, y; int ssx, eex, ssy, eey; int i; ! if( status == 0 ) { ! if( (dataPtr = (unsigned char *)arVideoGetImage()) == NULL ) { ! arUtilSleep(2); ! return; ! } ! dispImage2( dataPtr ); arVideoCapNext(); ! } ! ! else if( status == 1 ) { dispImage2( patt.savedImage[patt.loop_num-1] ); for( i = 0; i < point_num; i++ ) { x = patt.point[patt.loop_num-1][i].x_coord; --- 501,538 ---- } + static void Idle(void) + { + static int ms_prev; + int ms; + float s_elapsed; + ARUint8 *image; + + // Find out how long since Idle() last ran. + ms = glutGet(GLUT_ELAPSED_TIME); + s_elapsed = (float)(ms - ms_prev) * 0.001; + if (s_elapsed < 0.01f) return; // Don't update more often than 100 Hz. + ms_prev = ms; + + // Grab a video frame. + if ((image = arVideoGetImage()) != NULL) { + gARTImage = image; + // Tell GLUT the display has changed. + glutPostRedisplay(); + } + } + static void dispImage(void) { double x, y; int ssx, eex, ssy, eey; int i; ! if( gStatus == 0 ) { ! dispImage2(gARTImage); arVideoCapNext(); ! } else if( gStatus == 1 ) { dispImage2( patt.savedImage[patt.loop_num-1] ); + // Draw red crosses on the points in the image. for( i = 0; i < point_num; i++ ) { x = patt.point[patt.loop_num-1][i].x_coord; *************** *** 522,526 **** glEnd(); } ! if( sx != -1 && sy != -1 ) { if( sx < ex ) { ssx = sx; eex = ex; } --- 546,551 ---- glEnd(); } ! ! // Draw the current mouse drag clipping area. if( sx != -1 && sy != -1 ) { if( sx < ex ) { ssx = sx; eex = ex; } *************** *** 541,545 **** } ! else if( status == 2 ) { dispImage2( patt.savedImage[check_num] ); for( i = 0; i < patt.h_num*patt.v_num; i++ ) { --- 566,570 ---- } ! else if( gStatus == 2 ) { dispImage2( patt.savedImage[check_num] ); for( i = 0; i < patt.h_num*patt.v_num; i++ ) { *************** *** 789,794 **** } ! free( x ); ! free( y ); } --- 814,819 ---- } ! free(x); ! free(y); } *************** *** 800,821 **** int i; ! ev = arVecAlloc( 2 ); ! mean = arVecAlloc( 2 ); ! evec = arMatrixAlloc( 2, 2 ); ! input = arMatrixAlloc( num, 2 ); ! for( i = 0; i < num; i++ ) { ! arParamObserv2Ideal( dist_factor, x[i], y[i], ! &(input->m[i*2+0]), &(input->m[i*2+1]) ); } ! if( arMatrixPCA(input, evec, ev, mean) < 0 ) exit(0); a = evec->m[1]; b = -evec->m[0]; c = -(a*mean->v[0] + b*mean->v[1]); ! arMatrixFree( input ); ! arMatrixFree( evec ); ! arVecFree( mean ); ! arVecFree( ev ); draw_warp_line(a, b, c); --- 825,846 ---- int i; ! ev = arVecAlloc(2); ! mean = arVecAlloc(2); ! evec = arMatrixAlloc(2, 2); ! input = arMatrixAlloc(num, 2); ! for (i = 0; i < num; i++) { ! arParamObserv2Ideal(dist_factor, x[i], y[i], ! &(input->m[i*2+0]), &(input->m[i*2+1])); } ! if (arMatrixPCA(input, evec, ev, mean) < 0) exit(0); a = evec->m[1]; b = -evec->m[0]; c = -(a*mean->v[0] + b*mean->v[1]); ! arMatrixFree(input); ! arMatrixFree(evec); ! arVecFree(mean); ! arVecFree(ev); draw_warp_line(a, b, c); *************** *** 826,850 **** double x, y; double x1, y1; - // double d; // unreferenced int i; glLineWidth( 1.0 ); glBegin(GL_LINE_STRIP); ! if( a*a >= b*b ) { ! for( i = -20; i <= ysize+20; i+=10 ) { x = -(b*i + c)/a; y = i; ! arParamIdeal2Observ( dist_factor, x, y, &x1, &y1 ); ! glVertex2f( x1, ysize-1-y1 ); } ! } ! else { ! for( i = -20; i <= xsize+20; i+=10 ) { x = i; y = -(a*i + c)/b; ! arParamIdeal2Observ( dist_factor, x, y, &x1, &y1 ); ! glVertex2f( x1, ysize-1-y1 ); } } --- 851,873 ---- double x, y; double x1, y1; int i; glLineWidth( 1.0 ); glBegin(GL_LINE_STRIP); ! if (a*a >= b*b) { ! for (i = -20; i <= ysize+20; i+=10) { x = -(b*i + c)/a; y = i; ! arParamIdeal2Observ(dist_factor, x, y, &x1, &y1); ! glVertex2f(x1, ysize-1-y1); } ! } else { ! for(i = -20; i <= xsize+20; i+=10) { x = i; y = -(a*i + c)/b; ! arParamIdeal2Observ(dist_factor, x, y, &x1, &y1); ! glVertex2f(x1, ysize-1-y1); } } *************** *** 864,878 **** printf("Mouse Button\n"); printf(" Left : Rubber-bounding of feature. (%d x %d)\n", patt.h_num, patt.v_num); ! printf(" Right : Cansel rubber-bounding & Retry grabbing.\n"); break; case 2: printf("Mouse Button\n"); printf(" Left : Save feature position.\n"); ! printf(" Right : Discard & Retry grabbing.\n"); break; case 4: printf("Mouse Button\n"); printf(" Left : Grab next image.\n"); ! printf(" Right : Calc parameter.\n"); break; case 5: --- 887,901 ---- printf("Mouse Button\n"); printf(" Left : Rubber-bounding of feature. (%d x %d)\n", patt.h_num, patt.v_num); ! printf(" Right : Cancel rubber-bounding & retry grabbing.\n"); break; case 2: printf("Mouse Button\n"); printf(" Left : Save feature position.\n"); ! printf(" Right : Discard & retry grabbing.\n"); break; case 4: printf("Mouse Button\n"); printf(" Left : Grab next image.\n"); ! printf(" Right : Calculate parameter.\n"); break; case 5: *************** *** 885,889 **** printf("Mouse Button\n"); printf(" Left :\n"); ! printf(" Right : Calc parameter.\n"); printf(" %d/%d.\n", check_num+1, patt.loop_num); break; --- 908,912 ---- printf("Mouse Button\n"); printf(" Left :\n"); ! printf(" Right : Calculate parameter.\n"); printf(" %d/%d.\n", check_num+1, patt.loop_num); break; |