static void Idle(void) { static int ms_prev; int ms; float s_elapsed; ARUint8 *image; ARMarkerInfo *marker_info; // Pointer to array holding the details of detected markers. int marker_num; // Count of number of markers detected. int i, j, k; // 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; // Update drawing. arVrmlTimerUpdate(); // Grab a video frame. if ((image = arVideoGetImage()) != NULL) { gARTImage = image; // Save the fetched image. gPatt_found = FALSE; // Invalidate any previous detected markers. gCallCountMarkerDetect++; // Increment ARToolKit FPS counter. // Detect the markers in the video frame. if (arDetectMarker(gARTImage, gARTThreshhold, &marker_info, &marker_num) < 0) { exit(-1); } // Check for object visibility. for (i = 0; i < gObjectDataCount; i++) { // Check through the marker_info array for highest confidence // visible marker matching our object's pattern. k = -1; for (j = 0; j < marker_num; j++) { if (marker_info[j].id == gObjectData[i].id) { if( k == -1 ) k = j; // First marker detected. else if (marker_info[k].cf < marker_info[j].cf) k = j; // Higher confidence marker detected. } } if (k != -1) { // Get the transformation between the marker and the real camera. //fprintf(stderr, "Saw object %d.\n", i); if (gObjectData[i].visible == 0) { arGetTransMat(&marker_info[k], gObjectData[i].marker_center, gObjectData[i].marker_width, gObjectData[i].trans); } else { arGetTransMatCont(&marker_info[k], gObjectData[i].trans, gObjectData[i].marker_center, gObjectData[i].marker_width, gObjectData[i].trans); } gObjectData[i].visible = 1; gPatt_found = TRUE; } else { gObjectData[i].visible = 0; } } // Tell GLUT to update the display. glutPostRedisplay(); } }
static void mainLoop(void) { static int ms_prev; int ms; float s_elapsed; ARUint8 *image; ARdouble err; int i, j, k; // Find out how long since mainLoop() last ran. ms = glutGet(GLUT_ELAPSED_TIME); s_elapsed = (float)(ms - ms_prev) * 0.001f; if (s_elapsed < 0.01f) return; // Don't update more often than 100 Hz. ms_prev = ms; // Update drawing. arVrmlTimerUpdate(); // Grab a video frame. if ((image = arVideoGetImage()) != NULL) { gARTImage = image; // Save the fetched image. gCallCountMarkerDetect++; // Increment ARToolKit FPS counter. // Detect the markers in the video frame. if (arDetectMarker(gARHandle, gARTImage) < 0) { exit(-1); } // Check for object visibility. for (i = 0; i < gObjectDataCount; i++) { // Check through the marker_info array for highest confidence // visible marker matching our object's pattern. k = -1; for (j = 0; j < gARHandle->marker_num; j++) { if (gARHandle->markerInfo[j].id == gObjectData[i].id) { if (k == -1) k = j; // First marker detected. else if (gARHandle->markerInfo[j].cf > gARHandle->markerInfo[k].cf) k = j; // Higher confidence marker detected. } } if (k != -1) { // Get the transformation between the marker and the real camera. //ARLOGe("Saw object %d.\n", i); if (gObjectData[i].visible && useContPoseEstimation) { err = arGetTransMatSquareCont(gAR3DHandle, &(gARHandle->markerInfo[k]), gObjectData[i].trans, gObjectData[i].marker_width, gObjectData[i].trans); } else { err = arGetTransMatSquare(gAR3DHandle, &(gARHandle->markerInfo[k]), gObjectData[i].marker_width, gObjectData[i].trans); } gObjectData[i].visible = 1; } else { gObjectData[i].visible = 0; } } // Tell GLUT the display has changed. glutPostRedisplay(); } }