[artoolkit-commits] artoolkit/util/calib_camera2 main.c,1.7,1.8
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2005-09-22 00:44:45
|
Update of /cvsroot/artoolkit/artoolkit/util/calib_camera2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3222 Modified Files: main.c Log Message: Step 3 of cleanup. Index: main.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/util/calib_camera2/main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.c 14 Sep 2005 19:11:03 -0000 1.7 --- main.c 22 Sep 2005 00:44:37 -0000 1.8 *************** *** 154,158 **** // Start grabbing. ! point_num = 0; gStatus = 0; print_comment(0); --- 154,162 ---- // Start grabbing. ! if (arVideoCapStart() != 0) { ! fprintf(stderr, "init(): Unable to begin camera data capture.\n"); ! return (FALSE); ! } ! point_num = 0; gStatus = 0; print_comment(0); *************** *** 174,184 **** if (gPatt.h_num < 3 || gPatt.v_num < 3) exit(0); - #if CALIB_CAMERA2_DEBUG - length = 40.0; - #else printf("Input the distance between each marker dot, in millimeters: "); scanf("%lf", &length); while (getchar() != '\n'); ! #endif gPatt.world_coord = (CALIB_COORD_T *)malloc(sizeof(CALIB_COORD_T) * gPatt.h_num * gPatt.v_num); for (j = 0; j < gPatt.v_num; j++) { --- 178,185 ---- if (gPatt.h_num < 3 || gPatt.v_num < 3) exit(0); printf("Input the distance between each marker dot, in millimeters: "); scanf("%lf", &length); while (getchar() != '\n'); ! gPatt.world_coord = (CALIB_COORD_T *)malloc(sizeof(CALIB_COORD_T) * gPatt.h_num * gPatt.v_num); for (j = 0; j < gPatt.v_num; j++) { *************** *** 209,241 **** arMalloc(gClipImage, unsigned char, gXsize * gYsize); - if (arVideoCapStart() != 0) { - fprintf(stderr, "init(): Unable to begin camera data capture.\n"); - return (FALSE); - } - - return (TRUE); - } - - static int videoCleanup(void) - { - arVideoCapStop(); - arVideoClose(); return (TRUE); } static void grabImage(void) { // Processing a new image. ! // Copy the current image to saved image buffer. ! if (!gARTImage) return; gPatt.loop_num++; if ((gPatt.arglSettings[gPatt.loop_num-1] = arglSetupForCurrentContext()) == NULL) { ! fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n"); exit(-1); } arglDistortionCompensationSet(gPatt.arglSettings[gPatt.loop_num-1], FALSE); arMalloc((gPatt.savedImage)[gPatt.loop_num-1], unsigned char, gXsize*gYsize*AR_PIX_SIZE); ! memcpy((gPatt.savedImage)[gPatt.loop_num-1], gARTImage, gXsize*gYsize*AR_PIX_SIZE); printf("Grabbed image %d.\n", gPatt.loop_num); - arVideoCapStop(); arMalloc(gPatt.point[gPatt.loop_num-1], CALIB_COORD_T, gPatt.h_num*gPatt.v_num); } --- 210,233 ---- arMalloc(gClipImage, unsigned char, gXsize * gYsize); return (TRUE); } static void grabImage(void) { + ARUint8 *image; + // Processing a new image. ! // Copy an image to saved image buffer. ! do { ! image = arVideoGetImage(); ! } while (image == NULL); gPatt.loop_num++; if ((gPatt.arglSettings[gPatt.loop_num-1] = arglSetupForCurrentContext()) == NULL) { ! fprintf(stderr, "grabImage(): arglSetupForCurrentContext() returned error.\n"); exit(-1); } arglDistortionCompensationSet(gPatt.arglSettings[gPatt.loop_num-1], FALSE); arMalloc((gPatt.savedImage)[gPatt.loop_num-1], unsigned char, gXsize*gYsize*AR_PIX_SIZE); ! memcpy((gPatt.savedImage)[gPatt.loop_num-1], image, gXsize*gYsize*AR_PIX_SIZE); printf("Grabbed image %d.\n", gPatt.loop_num); arMalloc(gPatt.point[gPatt.loop_num-1], CALIB_COORD_T, gPatt.h_num*gPatt.v_num); } *************** *** 281,286 **** if (gStatus == 0) { // Cancelled grabbing. ! // Live video will not be needed from here on, so cleanup. ! videoCleanup(); if (gPatt.loop_num == 0) { // No images with all features identified, so quit. --- 273,278 ---- if (gStatus == 0) { // Cancelled grabbing. ! // Live video will not be needed from here on. ! arVideoCapStop(); if (gPatt.loop_num == 0) { // No images with all features identified, so quit. *************** *** 319,323 **** int i, j, k; ! if (button == GLUT_RIGHT_BUTTON) { eventCancel(); } else if (button == GLUT_LEFT_BUTTON) { --- 311,315 ---- int i, j, k; ! if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { eventCancel(); } else if (button == GLUT_LEFT_BUTTON) { *************** *** 328,331 **** --- 320,324 ---- grabImage(); gDragStartX = gDragStartY = gDragEndX = gDragEndY = -1; + arVideoCapStop(); gStatus = 1; print_comment(1); *************** *** 358,362 **** } } else if (state == GLUT_UP) { ! if (gStatus == 1 && point_num < gPatt.h_num*gPatt.v_num) { // Drag for rubber-bounding of a feature has finished. Begin identification // of center of white region in gClipImage. --- 351,358 ---- } } else if (state == GLUT_UP) { ! if (gStatus == 1 ! && gDragStartX != -1 && gDragStartY != -1 ! && gDragEndX != -1 && gDragEndY != -1 ! && point_num < gPatt.h_num*gPatt.v_num) { // Drag for rubber-bounding of a feature has finished. Begin identification // of center of white region in gClipImage. *************** *** 370,375 **** p = gClipImage; k = 0; ! for( j = 0; j < (eey-ssy+1); j++ ) { ! for( i = 0; i < (eex-ssx+1); i++ ) { gPatt.point[gPatt.loop_num-1][point_num].x_coord += i * *p; gPatt.point[gPatt.loop_num-1][point_num].y_coord += j * *p; --- 366,371 ---- p = gClipImage; k = 0; ! for (j = 0; j < (eey-ssy+1); j++) { ! for (i = 0; i < (eex-ssx+1); i++) { gPatt.point[gPatt.loop_num-1][point_num].x_coord += i * *p; gPatt.point[gPatt.loop_num-1][point_num].y_coord += j * *p; *************** *** 378,382 **** } } ! if( k != 0 ) { gPatt.point[gPatt.loop_num-1][point_num].x_coord /= k; gPatt.point[gPatt.loop_num-1][point_num].y_coord /= k; --- 374,378 ---- } } ! if (k != 0) { gPatt.point[gPatt.loop_num-1][point_num].x_coord /= k; gPatt.point[gPatt.loop_num-1][point_num].y_coord /= k; *************** *** 473,478 **** --- 469,479 ---- static void Quit(void) { + if (gClipImage) { + free(gClipImage); + gClipImage = NULL; + } if (gArglSettings) arglCleanup(gArglSettings); if (gWin) glutDestroyWindow(gWin); + arVideoClose(); exit(0); } *************** *** 542,549 **** static void endOrtho2D(void) { - glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } --- 543,550 ---- static void endOrtho2D(void) { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); + glPopMatrix(); } *************** *** 558,561 **** --- 559,564 ---- glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); beginOrtho2D(); *************** *** 564,567 **** --- 567,571 ---- arglDispImage(gARTImage, &gARTCparam, 1.0, gArglSettings); // zoom = 1.0. arVideoCapNext(); + gARTImage = NULL; } else if (gStatus == 1) { *************** *** 572,586 **** x = gPatt.point[gPatt.loop_num-1][i].x_coord; y = gPatt.point[gPatt.loop_num-1][i].y_coord; ! glColor3f( 1.0, 0.0, 0.0 ); glBegin(GL_LINES); ! glVertex2f( x-10, (gYsize-1)-y ); ! glVertex2f( x+10, (gYsize-1)-y ); ! glVertex2f( x, (gYsize-1)-(y-10) ); ! glVertex2f( x, (gYsize-1)-(y+10) ); glEnd(); } // Draw the current mouse drag clipping area. ! if (gDragStartX != -1 && gDragStartY != -1) { if (gDragStartX < gDragEndX) { ssx = gDragStartX; eex = gDragEndX; } else { ssx = gDragEndX; eex = gDragStartX; } --- 576,591 ---- x = gPatt.point[gPatt.loop_num-1][i].x_coord; y = gPatt.point[gPatt.loop_num-1][i].y_coord; ! glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINES); ! glVertex2d(x-10.0, (GLdouble)(gYsize-1)-y); ! glVertex2d(x+10.0, (GLdouble)(gYsize-1)-y); ! glVertex2d(x, (GLdouble)(gYsize-1)-(y-10.0)); ! glVertex2d(x, (GLdouble)(gYsize-1)-(y+10.0)); glEnd(); } // Draw the current mouse drag clipping area. ! if (gDragStartX != -1 && gDragStartY != -1 ! && gDragEndX != -1 && gDragEndY != -1) { if (gDragStartX < gDragEndX) { ssx = gDragStartX; eex = gDragEndX; } else { ssx = gDragEndX; eex = gDragStartX; } *************** *** 590,594 **** if (gClipImage) { glPixelZoom(1.0f, -1.0f); // ARToolKit bitmap 0.0 is at upper-left, OpenGL bitmap 0.0 is at lower-left. ! glRasterPos2f((GLfloat)ssx, (GLfloat)gYsize-1-ssy); glDrawPixels(eex-ssx+1, eey-ssy+1, GL_LUMINANCE, GL_UNSIGNED_BYTE, gClipImage); } --- 595,600 ---- if (gClipImage) { glPixelZoom(1.0f, -1.0f); // ARToolKit bitmap 0.0 is at upper-left, OpenGL bitmap 0.0 is at lower-left. ! glRasterPos2f((GLfloat)(ssx), (GLfloat)(gYsize-1-ssy)); ! glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glDrawPixels(eex-ssx+1, eey-ssy+1, GL_LUMINANCE, GL_UNSIGNED_BYTE, gClipImage); } *************** *** 596,603 **** glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINE_LOOP); ! glVertex2f(gDragStartX, (gYsize-1)-gDragStartY); ! glVertex2f(gDragEndX, (gYsize-1)-gDragStartY); ! glVertex2f(gDragEndX, (gYsize-1)-gDragEndY); ! glVertex2f(gDragStartX, (gYsize-1)-gDragEndY); glEnd(); #endif --- 602,609 ---- glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINE_LOOP); ! glVertex2i(gDragStartX, (gYsize-1)-gDragStartY); ! glVertex2i(gDragEndX, (gYsize-1)-gDragStartY); ! glVertex2i(gDragEndX, (gYsize-1)-gDragEndY); ! glVertex2i(gDragStartX, (gYsize-1)-gDragEndY); glEnd(); #endif *************** *** 610,619 **** x = gPatt.point[check_num][i].x_coord; y = gPatt.point[check_num][i].y_coord; ! glColor3f( 1.0, 0.0, 0.0 ); glBegin(GL_LINES); ! glVertex2f( x-10, (gYsize-1)-y ); ! glVertex2f( x+10, (gYsize-1)-y ); ! glVertex2f( x, (gYsize-1)-(y-10) ); ! glVertex2f( x, (gYsize-1)-(y+10) ); glEnd(); } --- 616,625 ---- x = gPatt.point[check_num][i].x_coord; y = gPatt.point[check_num][i].y_coord; ! glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINES); ! glVertex2d(x-10.0, (GLdouble)(gYsize-1)-y); ! glVertex2d(x+10.0, (GLdouble)(gYsize-1)-y); ! glVertex2d(x, (GLdouble)(gYsize-1)-(y-10.0)); ! glVertex2d(x, (GLdouble)(gYsize-1)-(y+10.0)); glEnd(); } *************** *** 747,766 **** case 0: printf("Press mouse button to grab first image,\n"); ! printf("or press [esc] to quit.\n"); break; case 1: printf("Press mouse button and drag mouse to rubber-bound features (%d x %d),\n", gPatt.h_num, gPatt.v_num); ! printf("or press [esc] to cancel rubber-bounding & retry grabbing.\n"); break; case 2: printf("Press mouse button to save feature positions,\n"); ! printf("or press [esc] to discard feature positions & retry grabbing.\n"); break; case 4: printf("Press mouse button to grab next image,\n"); ! printf("or press [esc] to calculate distortion parameter.\n"); break; case 5: ! printf("Press [esc] to calculate distortion parameter.\n"); break; } --- 753,772 ---- case 0: printf("Press mouse button to grab first image,\n"); ! printf("or press right mouse button or [esc] to quit.\n"); break; case 1: printf("Press mouse button and drag mouse to rubber-bound features (%d x %d),\n", gPatt.h_num, gPatt.v_num); ! printf("or press right mouse button or [esc] to cancel rubber-bounding & retry grabbing.\n"); break; case 2: printf("Press mouse button to save feature positions,\n"); ! printf("or press right mouse button or [esc] to discard feature positions & retry grabbing.\n"); break; case 4: printf("Press mouse button to grab next image,\n"); ! printf("or press right mouse button or [esc] to calculate distortion parameter.\n"); break; case 5: ! printf("Press right mouse button or [esc] to calculate distortion parameter.\n"); break; } |