Ejemplo n.º 1
0
bool ofxArtool5::setupPattern(ofVec2f _camSize, ofVec2f _viewportSize, ofPixelFormat pf, string pthCamParam, string pthMarker){
    
    artMode=ART_PATTERN;
    curArtMode=(ofxArtoolMode*)(new ofxArtoolModePatt());
    curArtMode->gCparamLT=gCparamLT;
    
    if(!setupCamera(pthCamParam, _camSize, _viewportSize)){
        return false;
    }
    
    return true;
    
    artMode=ART_PATTERN;
    curArtMode = (ofxArtoolMode * )(new ofxArtoolModePatt());
    curArtMode->gCparamLT = gCparamLT;
    
    bPattFound = false;
    selectedId = -1;
    
    if(!setupCamera(pthCamParam, _camSize, _viewportSize)){
        return false;
    }
    
    arUtilTimerReset();
    
    if(!setupMarker(pthMarker)){
        cleanup();
        return false;
    }
    
    return true;
}
Ejemplo n.º 2
0
/* main loop */
static void mainLoop(void)
{
    int             i, j, k;

    if( count == 100 ) {
        printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
        count = 0;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0, 0 );

    /* if the debug mode is on draw squares 
       around the detected squares in the video image */
    if( arDebug ) {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 2, 1 );
        else
            argDispImage( arImage, 2, 1);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 3.0 );
        for( i = 0; i < marker_num; i++ ) {
            if( marker_info[i].id < 0 ) continue;
            argDrawSquare( marker_info[i].vertex, 2, 1 );
        }
        glLineWidth( 1.0 );
    }

    argSwapBuffers();
}
Ejemplo n.º 3
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }
	
	
	//additions from sheyne, trying to understand how it is working.
	
	//from documentation on http://artoolkit.sourceforge.net/apidoc/structARMarkerInfo.html
	
	//also look at: http://www.hitl.washington.edu/artoolkit/documentation/devframework.htm
	printf("pos: %f,%f\n", marker_info->pos[0], marker_info->pos[1]);
	for (j=0; j<4; j++) {
		printf("\t vertex: %f, %f\n", marker_info->vertex[j][0],marker_info->vertex[j][1]);
	}
	
    arVideoCapNext();

    /* check for object visibility */
    k = -1;
    for( j = 0; j < marker_num; j++ ) {
        if( patt_id == marker_info[j].id ) {
            if( k == -1 ) k = j;
            else if( marker_info[k].cf < marker_info[j].cf ) k = j;
        }
    }
    if( k == -1 ) {
        argSwapBuffers();
        return;
    }

    /* get the transformation between the marker and the real camera */
    arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);

    draw();

    argSwapBuffers();
}
Ejemplo n.º 4
0
static void Keyboard(unsigned char key, int x, int y)
{
	int mode;
	switch (key) {
		case 0x1B:						// Quit.
		case 'r':
			knight->Reset();
		case 'x':
			knight->TranslateX(0.1);
			break;
		case 'y':
			knight->TranslateY(0.1);
			break;
		case 'z':
			knight->TranslateZ(0.1);
			break;
		case 'Q':
		case 'q':
			Quit();
			break;
		case ' ':
			gDrawRotate = !gDrawRotate;
			break;
		case 'C':
		case 'c':
			mode = arglDrawModeGet(gArglSettings);
			if (mode == AR_DRAW_BY_GL_DRAW_PIXELS) {
				arglDrawModeSet(gArglSettings, AR_DRAW_BY_TEXTURE_MAPPING);
				arglTexmapModeSet(gArglSettings, AR_DRAW_TEXTURE_FULL_IMAGE);
			} else {
				mode = arglTexmapModeGet(gArglSettings);
				if (mode == AR_DRAW_TEXTURE_FULL_IMAGE)	arglTexmapModeSet(gArglSettings, AR_DRAW_TEXTURE_HALF_IMAGE);
				else arglDrawModeSet(gArglSettings, AR_DRAW_BY_GL_DRAW_PIXELS);
			}
			fprintf(stderr, "*** Camera - %f (frame/sec)\n", (double)gCallCountMarkerDetect/arUtilTimer());
			gCallCountMarkerDetect = 0;
			arUtilTimerReset();
			debugReportMode();
			break;
		case 'D':
		case 'd':
			arDebug = !arDebug;
			break;
		case '?':
		case '/':
			printf("Keys:\n");
			printf(" q or [esc]    Quit demo.\n");
			printf(" c             Change arglDrawMode and arglTexmapMode.\n");
			printf(" d             Activate / deactivate debug mode.\n");
			printf(" ? or /        Show this help.\n");
			printf("\nAdditionally, the ARVideo library supplied the following help text:\n");
			arVideoDispOption();
			break;
		default:
			break;
	}
}
Ejemplo n.º 5
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;


	if (dataPtr = GetNextImage()) {
	
		if( count == 0 ) arUtilTimerReset();
		count++;
		argDrawMode2D();
		argDispImage( dataPtr, 0,0 );

		/* detect the markers in the video frame */ 
		if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
			printf("could'nt find any marker");
			cleanup();
			exit(0);
		}
		//else printf("i found the marker"); 




		/* check for object visibility */
		k = -1;
		for( j = 0; j < marker_num; j++ ) {
			if( patt_id == marker_info[j].id ) {
				if( k == -1 ) k = j;
				else if( marker_info[k].cf < marker_info[j].cf ) k = j;
			}
		}
		if( k == -1 ) {
			argSwapBuffers();
			return;
		}

		/* get the transformation between the marker and the real camera */
		arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);

		if (geometry == 0) {
			draw();
		} else {
			geometryout();
		}

		argSwapBuffers();
	} else  {
		
		printf("Done - press any key \n");
		getchar();
		exit(0);
	}

}
int main(int argc, char** argv) {
	char glutGamemode[32];
	glutInit(&argc, argv);
	setup_camera();
	setup_marker();
	init_voxels_hp();

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(prefWidth, prefHeight);
	camera_win_id = glutCreateWindow("Camera");
	glutTimerFunc(10, TimeEvent, 1);

	ARGL_CONTEXT_SETTINGS_REF argl_context_ref = NULL;
	// Setup argl library for current context.
	if ((argl_context_ref = arglSetupForCurrentContext()) == NULL) {
		std::cout << "main(): arglSetupForCurrentContext() returned error." << std::endl;
		exit(-1);
	}

	arUtilTimerReset();

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glutVisibilityFunc(visibility_camera);
	glutIdleFunc(idle_camera);
	glutDisplayFunc(display_camera);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(debug_only);
	setup_voxels();
	camera_set_context(argl_context_ref);
	
	viewer_win_id = glutCreateWindow("Viewer");
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
	glClearColor(0.0,0.0,0.0,1.0);
	glutVisibilityFunc(visibility_viewer);
	glutIdleFunc(idle_viewer);
	glutDisplayFunc(display_viewer);
	glutReshapeFunc(reshape_viewer);

	auto voxel_t = std::thread(voxel_carving_routine);
	auto capture_t = std::thread(image_capturing_routine);
	auto should_capture_t = std::thread(should_capture_routine);
	auto a_cam_buffer_t = std::thread(transfer);
	
	voxel_t.detach();
	capture_t.detach();
	should_capture_t.detach();
	a_cam_buffer_t.detach();

	glutMainLoop();

	return 0;
}
Ejemplo n.º 7
0
/* main loop */
static void mainLoop(void)
{
    static int      contF = 0;
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    arVideoCapNext();

    /* check for object visibility */
    k = -1;
    for( j = 0; j < marker_num; j++ ) {
        if( patt_id == marker_info[j].id ) {
            if( k == -1 ) k = j;
            else if( marker_info[k].cf < marker_info[j].cf ) k = j;
        }
    }
    if( k == -1 ) {
        contF = 0;
        argSwapBuffers();
        return;
    }

    /* get the transformation between the marker and the real camera */
    if( mode == 0 || contF == 0 ) {
        arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
		
    }
    else {
        arGetTransMatCont(&marker_info[k], patt_trans, patt_center, patt_width, patt_trans);
    }
    contF = 1;

    draw( patt_trans );

    argSwapBuffers();
}
Ejemplo n.º 8
0
int main(int argc,char**argv){

    ARParam cparam;
    ARParam wparam;
    int xsize,ysize;
    glutInit(&argc,argv);

    if(arVideoOpen(vconf_name)<0){
	puts("ビデオデバイスエラー");
	return -1;
    }

    if(arVideoInqSize(&xsize,&ysize) < 0)return -1;

    if(arParamLoad(cparam_name,1,&wparam)< 0){
	puts("パラメータ読み込み失敗");
	return -1;
    }

    arParamChangeSize(&wparam,xsize,ysize,&cparam);
    arInitCparam(&cparam);
    nyobj = nyar_NyARTransMat_O2_create(&cparam);

    if( (patt_id=arLoadPatt(pattern_name)) < 0){
	puts("パターン読み込みエラー");
	return -1;
    }

    argInit(&cparam, 1.0, 0, 0, 0, 0); 
    mqoInit();

    if(Data_Load()==-1)
	return -1;

    arVideoCapStart();
    InitGame();

    arUtilTimerReset();
#ifdef _WIN32
    TIMECAPS Caps;
    timeGetDevCaps(&Caps, sizeof(TIMECAPS)); // 性能取得
    timeBeginPeriod(Caps.wPeriodMin);
#endif
    argMainLoop(MouseEvent,KeyEvent,MainLoop);
#ifdef _WIN32
    timeEndPeriod(Caps.wPeriodMin);
#endif
    nyar_NyARTransMat_O2_free(nyobj);
    return 0;


}
Ejemplo n.º 9
0
	static void mainLoop() {
		ARUint8         *dataPtr;
		ARMarkerInfo    *marker_info;
		int             marker_num;
		int             j, k;

		//Get video frame
		if ((dataPtr = (ARUint8 *)arVideoGetImage()) == NULL) {
			arUtilSleep(2);
			return;
		}
		if (count == 0) {
			arUtilTimerReset();
		}
		count++;

		//Display video stream
		argDrawMode2D();
		argDispImage(dataPtr, 0, 0);

		/* detect the markers in the video frame */
		if (arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0) {
			cleanup();
			exit(0);
		}

		//Get next video frame
		arVideoCapNext();

		/* check for object visibility */
		k = -1;
		for (j = 0; j < marker_num; j++) {
			if (patt_id == marker_info[j].id) {
				if (k == -1) k = j;
				else if (marker_info[k].cf < marker_info[j].cf) k = j;
			}
		}

		//Don't bother drawing or calculating orientations if no patterns are found
		if (k == -1) {
			argSwapBuffers();
			return;
		}

		/* get the transformation between the marker and the real camera */
		arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);

		draw();

		argSwapBuffers();
	}
/* main loop */
static void mainLoop(void)
{

	if( count == 100 ) {
        printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
        count = 0;
    }
	if( count == 0 ) arUtilTimerReset();
    count++;

	rotate_angle+=1.;
	if (rotate_angle>360)
	{
		rotate_angle=0.;
	}
    draw();

    argSwapBuffers();
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    init(argc, argv);

    argSetWindow(w1);
    argSetDispFunc(mainLoop, 1);
    argSetKeyFunc(keyEvent);

    argSetWindow(w2);
    argSetDispFunc(mainLoop, 1);
    argSetKeyFunc(keyEvent);

    count  = 0;
    fps[0] = '\0';
    arVideoCapStart();
    arUtilTimerReset();
    argMainLoop();
    return (0);
}
Ejemplo n.º 12
0
bool ofxArtool5::setupNFT(ofVec2f _camSize, ofVec2f _viewportSize, ofPixelFormat pf, string pthCamParam, string pthMarkerData){
    artMode=ART_NFT;
    bPattFound = false;
    
    if(!setupCamera(pthCamParam, _camSize, _viewportSize)){
        return false;
    }
    
    if(!initNFT(gCparamLT, toAR(pf))){
        return false;
    }
    
    arUtilTimerReset();
    
    const char * cMarkerData = ofToDataPath(pthMarkerData).c_str();
    newMarkers(cMarkerData, &markersNFT, &markersNFTCount);
    if(!markersNFTCount){
        ofLogError("ofxArtool5::setupNFT","error loading markers from file");
        cleanup();
        return false;
    }
    
    return true;
}
Ejemplo n.º 13
0
static void Keyboard(unsigned char key, int x, int y)
{
	int mode, threshChange = 0;
    AR_LABELING_THRESH_MODE modea;
	
	switch (key) {
		case 0x1B:						// Quit.
		case 'Q':
		case 'q':
			cleanup();
			exit(0);
			break;
		case ' ':
			gDrawRotate = !gDrawRotate;
			break;
		case 'X':
		case 'x':
            arGetImageProcMode(gARHandle, &mode);
            switch (mode) {
                case AR_IMAGE_PROC_FRAME_IMAGE:  mode = AR_IMAGE_PROC_FIELD_IMAGE; break;
                case AR_IMAGE_PROC_FIELD_IMAGE:
                default: mode = AR_IMAGE_PROC_FRAME_IMAGE; break;
            }
            arSetImageProcMode(gARHandle, mode);
			break;
		case 'C':
		case 'c':
			mode = arglDrawModeGet(gArglSettings);
			if (mode == AR_DRAW_BY_GL_DRAW_PIXELS) {
				arglDrawModeSet(gArglSettings, AR_DRAW_BY_TEXTURE_MAPPING);
				arglTexmapModeSet(gArglSettings, AR_DRAW_TEXTURE_FULL_IMAGE);
			} else {
				mode = arglTexmapModeGet(gArglSettings);
				if (mode == AR_DRAW_TEXTURE_FULL_IMAGE)	arglTexmapModeSet(gArglSettings, AR_DRAW_TEXTURE_HALF_IMAGE);
				else arglDrawModeSet(gArglSettings, AR_DRAW_BY_GL_DRAW_PIXELS);
			}
			ARLOGe("*** Camera - %f (frame/sec)\n", (double)gCallCountMarkerDetect/arUtilTimer());
			gCallCountMarkerDetect = 0;
			arUtilTimerReset();
			break;
		case 'a':
		case 'A':
			arGetLabelingThreshMode(gARHandle, &modea);
            switch (modea) {
                case AR_LABELING_THRESH_MODE_MANUAL:        modea = AR_LABELING_THRESH_MODE_AUTO_MEDIAN; break;
                case AR_LABELING_THRESH_MODE_AUTO_MEDIAN:   modea = AR_LABELING_THRESH_MODE_AUTO_OTSU; break;
                case AR_LABELING_THRESH_MODE_AUTO_OTSU:     modea = AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE; break;
                case AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE: modea = AR_LABELING_THRESH_MODE_AUTO_BRACKETING; break;
                case AR_LABELING_THRESH_MODE_AUTO_BRACKETING:
                default: modea = AR_LABELING_THRESH_MODE_MANUAL; break;
            }
            arSetLabelingThreshMode(gARHandle, modea);
			break;
		case '-':
			threshChange = -5;
			break;
		case '+':
		case '=':
			threshChange = +5;
			break;
		case 'D':
		case 'd':
			arGetDebugMode(gARHandle, &mode);
			arSetDebugMode(gARHandle, !mode);
			break;
        case 's':
        case 'S':
            if (!gARTImageSavePlease) gARTImageSavePlease = TRUE;
            break;
		case '?':
		case '/':
            gShowHelp++;
            if (gShowHelp > 1) gShowHelp = 0;
			break;
        case 'm':
        case 'M':
            gShowMode = !gShowMode;
            break;
		default:
			break;
	}
	if (threshChange) {
		int threshhold;
		arGetLabelingThresh(gARHandle, &threshhold);
		threshhold += threshChange;
		if (threshhold < 0) threshhold = 0;
		if (threshhold > 255) threshhold = 255;
		arSetLabelingThresh(gARHandle, threshhold);
	}
	
}
Ejemplo n.º 14
0
static void mainLoop(void)
{
    ARUint8      *dataPtr;
    ARMarkerInfo *markerInfo;
    int          markerNum;
    ARdouble     patt_trans[3][4];
    ARdouble     err;
    int          imageProcMode;
    int          debugMode;
    int          j, k;

    /* grab a video frame */
    if ((dataPtr = (ARUint8*)arVideoGetImage()) == NULL)
    {
        arUtilSleep(2);
        return;
    }

    /* detect the markers in the video frame */
    if (arDetectMarker(arHandle, dataPtr) < 0)
    {
        cleanup();
        exit(0);
    }

    argSetWindow(w1);
    argDrawMode2D(vp1);
    arGetDebugMode(arHandle, &debugMode);
    if (debugMode == 0)
    {
        argDrawImage(dataPtr);
    }
    else
    {
        arGetImageProcMode(arHandle, &imageProcMode);
        if (imageProcMode == AR_IMAGE_PROC_FRAME_IMAGE)
        {
            argDrawImage(arHandle->labelInfo.bwImage);
        }
        else
        {
            argDrawImageHalf(arHandle->labelInfo.bwImage);
        }
    }

    argSetWindow(w2);
    argDrawMode2D(vp2);
    argDrawImage(dataPtr);
    argSetWindow(w1);

    if (count % 10 == 0)
    {
        sprintf(fps, "%f[fps]", 10.0 / arUtilTimer());
        arUtilTimerReset();
    }

    count++;
    glColor3f(0.0f, 1.0f, 0.0f);
    argDrawStringsByIdealPos(fps, 10, ysize - 30);

    markerNum = arGetMarkerNum(arHandle);
    if (markerNum == 0)
    {
        argSetWindow(w1);
        argSwapBuffers();
        argSetWindow(w2);
        argSwapBuffers();
        return;
    }

    /* check for object visibility */
    markerInfo = arGetMarker(arHandle);
    k          = -1;

    for (j = 0; j < markerNum; j++)
    {
        // ARLOG("ID=%d, CF = %f\n", markerInfo[j].id, markerInfo[j].cf);
        if (patt_id == markerInfo[j].id)
        {
            if (k == -1)
            {
                if (markerInfo[j].cf > 0.7)
                    k = j;
            }
            else if (markerInfo[j].cf > markerInfo[k].cf)
                k = j;
        }
    }

    if (k == -1)
    {
        argSetWindow(w1);
        argSwapBuffers();
        argSetWindow(w2);
        argSwapBuffers();
        return;
    }

    err = arGetTransMatSquare(ar3DHandle, &(markerInfo[k]), patt_width, patt_trans);
    sprintf(errValue, "err = %f", err);
    glColor3f(0.0f, 1.0f, 0.0f);
    argDrawStringsByIdealPos(fps, 10, ysize - 30);
    argDrawStringsByIdealPos(errValue, 10, ysize - 60);
    // ARLOG("err = %f\n", err);

    draw(patt_trans);

    argSetWindow(w1);
    argSwapBuffers();
    argSetWindow(w2);
    argSwapBuffers();
}
Ejemplo n.º 15
0
/*
 * Class:     net_towerdefender_image_MarkerInfo
 * Method:    artoolkit_detectmarkers
 * Signature: ([B[D)I
 */
JNIEXPORT jint JNICALL Java_net_towerdefender_image_ARToolkit_artoolkit_1detectmarkers(
		JNIEnv *env, jobject object, jbyteArray image, jobject transMatMonitor) {
	ARUint8 *dataPtr;
	ARMarkerInfo *marker_info;
	double *matrixPtr;
	int marker_num;
	int j, k = -1;
	Object* curObject;

	/* grab a vide frame */
	dataPtr = (*env)->GetByteArrayElements(env, image, JNI_FALSE);
	if (count == 0)
		arUtilTimerReset();
	count++;

	/* detect the markers in the video frame */
	if (arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0) {
		__android_log_write(ANDROID_LOG_ERROR, "AR native",
				"arDetectMarker failed!!");
		jclass exc = (*env)->FindClass(env,
				"net/towerdefender/exceptions/ARException");
		if (exc != NULL)
			(*env)->ThrowNew(env, exc, "failed to detect marker");
	}
#ifdef DEBUG_LOGGING
	__android_log_print(ANDROID_LOG_INFO,"AR native","detected %d markers",marker_num);
#endif

	//lock the matrix
	/*(*env)->MonitorEnter(env, transMatMonitor);
	 cur_marker_id = k;
	 argConvGlpara(patt_trans, gl_para);
	 (*env)->MonitorExit(env, transMatMonitor);*/

	static jfieldID visibleField = NULL;
	static jfieldID glMatrixField = NULL;
	static jfieldID transMatField = NULL;
	static jfieldID vertexField = NULL;
	//static jfieldID dirField = NULL;
	jclass arObjectClass = NULL;
	jfloatArray glMatrixArrayObj = NULL;
	jdoubleArray transMatArrayObj = NULL;
	jdoubleArray vertexArrayObj = NULL;
	//jint dirObj = NULL;

#ifdef DEBUG_LOGGING
	__android_log_write(ANDROID_LOG_INFO,"AR native","done detecting markers, going to iterate over markers now");
#endif
	//iterate over objects:
	list_iterator_start(&objects); /* starting an iteration "session" */
	int itCount = 0;
	while (list_iterator_hasnext(&objects)) { /* tell whether more values available */
		curObject = (Object *) list_iterator_next(&objects); /* get the next value */
#ifdef DEBUG_LOGGING
		__android_log_print(ANDROID_LOG_INFO,"AR native","now handling object with id %d, in %d iteration",curObject->name, itCount);
#endif
		itCount++;
		// //get field ID'		
		if (visibleField == NULL) {
			if (arObjectClass == NULL) {
				if (curObject->objref != NULL)
					arObjectClass = (*env)->GetObjectClass(env,
							curObject->objref);
			}
			if (arObjectClass != NULL) {
				visibleField = (*env)->GetFieldID(env, arObjectClass, "visible",
						"Z");				//Z means boolean
			}
		}
		if (glMatrixField == NULL) {
			if (arObjectClass == NULL) {
				if (curObject->objref != NULL)
					arObjectClass = (*env)->GetObjectClass(env,
							curObject->objref);
			}
			if (arObjectClass != NULL) {
				glMatrixField = (*env)->GetFieldID(env, arObjectClass,
						"glMatrix", "[F");			//[F means array of floats
			}
		}

		if (transMatField == NULL) {
			if (arObjectClass == NULL) {
				if (curObject->objref != NULL)
					arObjectClass = (*env)->GetObjectClass(env,
							curObject->objref);
			}
			if (arObjectClass != NULL) {
				transMatField = (*env)->GetFieldID(env, arObjectClass,
						"transMat", "[D");			//[D means array of doubles
			}
		}
		if (vertexField == NULL) {
			if (arObjectClass == NULL) {
				if (curObject->objref != NULL)
					arObjectClass = (*env)->GetObjectClass(env,
							curObject->objref);
			}
			if (arObjectClass != NULL) {
				vertexField = (*env)->GetFieldID(env, arObjectClass, "vertexMat",
						"[D");				//[F means array of floats
			}
		}
		/*if (dirField == NULL) {
					if (arObjectClass == NULL) {
						if (curObject->objref != NULL)
							arObjectClass = (*env)->GetObjectClass(env,
									curObject->objref);
					}
					if (arObjectClass != NULL) {
						dirField = (*env)->GetFieldID(env, arObjectClass, "dir",
								"I");				//[F means array of floats
					}
				}

*/
		if (visibleField == NULL || glMatrixField == NULL
				|| transMatField == NULL /*|| dirField == NULL*/) {
			//something went wrong..
#ifdef DEBUG_LOGGING
			__android_log_write(ANDROID_LOG_INFO,"AR native","error: either visibleField or glMatrixField or transMatField null");
#endif
			continue;
		}

		// check for object visibility
		k = -1;
		for (j = 0; j < marker_num; j++) {
#ifdef DEBUG_LOGGING
			__android_log_print(ANDROID_LOG_INFO,"AR native","marker with id: %d", marker_info[j].id);
#endif
			if (curObject->id == marker_info[j].id) {
				if (k == -1) {
					k = j;
#ifdef DEBUG_LOGGING
					__android_log_print(ANDROID_LOG_INFO,"AR native","detected object %d with marker %d and object marker %d",curObject->name,k,curObject->id);
#endif
				} else if (marker_info[k].cf < marker_info[j].cf) {
#ifdef DEBUG_LOGGING
					__android_log_print(ANDROID_LOG_INFO,"AR native","detected better object %d with marker %d and object marker %d",curObject->name,k,curObject->id);
#endif
					k = j;
				}
			}
		}
		if (k == -1) {
			//object not visible
			curObject->contF = 0;
			(*env)->SetBooleanField(env, curObject->objref, visibleField,
					JNI_FALSE);
#ifdef DEBUG_LOGGING
			__android_log_print(ANDROID_LOG_INFO,"AR native","object %d  not visible, with marker ID %d",curObject->name,curObject->id);
#endif
			continue;
		}
		//object visible

		//lock the object
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","locking object");
#endif
		(*env)->MonitorEnter(env, curObject->objref);
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","done locking object...obtaining arrays");
#endif
		//access the arrays of the current object
		glMatrixArrayObj = (*env)->GetObjectField(env, curObject->objref,
				glMatrixField);
		transMatArrayObj = (*env)->GetObjectField(env, curObject->objref,
				transMatField);
		vertexArrayObj = (*env)->GetObjectField(env, curObject->objref,
				vertexField);
		/*dirObj = (*env)->GetObjectField(env, curObject->objref,
						dirField);*/
		if (transMatArrayObj == NULL || glMatrixArrayObj == NULL || vertexArrayObj == NULL /*|| dirObj == NULL*/) {
#ifdef DEBUG_LOGGING
			__android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays objects");
#endif
			continue;				//something went wrong
		}
		float *glMatrix = (*env)->GetFloatArrayElements(env, glMatrixArrayObj,
				JNI_FALSE);
		if (glMatrix == NULL) {
#ifdef DEBUG_LOGGING
			__android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays");
#endif
			continue;				//something went wrong
		}
		double *vertexMatrix = (*env)->GetDoubleArrayElements(env, vertexArrayObj,
				JNI_FALSE);
		if (vertexMatrix == NULL) {
#ifdef DEBUG_LOGGING
			__android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the vertex arrays");
#endif
			continue;				//something went wrong
		}

		double* transMat = (*env)->GetDoubleArrayElements(env, transMatArrayObj,
				JNI_FALSE);
		if (transMat == NULL) {
#ifdef DEBUG_LOGGING
			__android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays");
#endif
			continue;				//something went wrong
		}
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","calculating trans mat now");
#endif

		/*int* dirPtr = (*env)->GetIntArrayElements(env, dirObj,
						JNI_FALSE);
				if (dirPtr == NULL) {
		#ifdef DEBUG_LOGGING
					__android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays");
		#endif
					continue;				//something went wrong
				}
		#ifdef DEBUG_LOGGING
				__android_log_write(ANDROID_LOG_INFO,"AR native","calculating trans mat now");
		#endif
*/
		// get the transformation between the marker and the real camera 
		if (curObject->contF == 0) {
			arGetTransMat(&marker_info[k], curObject->marker_center,
					curObject->marker_width, transMat);
		} else {
			arGetTransMatCont(&marker_info[k], transMat,
					curObject->marker_center, curObject->marker_width,
					transMat);
		}
		curObject->contF = 1;
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","calculating OpenGL trans mat now");
#endif
		argConvGlpara(transMat, glMatrix);
		int vertexId = 0;
		double inx,iny,outx,outy;
		for (vertexId = 0 ; vertexId < 8 ; vertexId+=2)
		{
			inx = ((double *)marker_info[k].vertex)[vertexId];
			iny = ((double *)marker_info[k].vertex)[vertexId+1];
			arParamIdeal2Observ	( arParam.dist_factor, inx,iny,&outx,&outy);
			vertexMatrix[vertexId] = outx;
			vertexMatrix[vertexId+1] = outy;
		}

		//*dirPtr = marker_info[k].dir;
		//argConvGlpara(patt_trans, gl_para);
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","releasing arrays");
#endif
		(*env)->ReleaseFloatArrayElements(env, glMatrixArrayObj, glMatrix, 0);
		(*env)->ReleaseDoubleArrayElements(env, transMatArrayObj, transMat, 0);
		(*env)->ReleaseDoubleArrayElements(env, vertexArrayObj, vertexMatrix, 0);
		//(*env)->ReleaseDoubleArrayElements(env, dirObj, dirPtr, 0);

		(*env)->SetBooleanField(env, curObject->objref, visibleField, JNI_TRUE);
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","releasing lock");
#endif		
		//release the lock on the object
		(*env)->MonitorExit(env, curObject->objref);
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","done releasing lock");
#endif
	}
	list_iterator_stop(&objects); /* starting the iteration "session" */
#ifdef DEBUG_LOGGING
	__android_log_write(ANDROID_LOG_INFO,"AR native","releasing image array");
#endif
	(*env)->ReleaseByteArrayElements(env, image, dataPtr, 0);
#ifdef DEBUG_LOGGING
	__android_log_write(ANDROID_LOG_INFO,"AR native","releasing image array");
#endif
	return marker_num;
}
Ejemplo n.º 16
0
static void mainLoop(void)
{
	static int ms_prev;
	int ms;
	float s_elapsed;
	ARUint8 *image;


    int             i, j, k;
	
	// Calculate time delta.
	ms = glutGet(GLUT_ELAPSED_TIME);
	s_elapsed = (float)(ms - ms_prev) * 0.001f;
	ms_prev = ms;
	
	// Grab a video frame.
	if ((image = arVideoGetImage()) != NULL) {
		gARTImage = image;	// Save the fetched image.
		
        // Calculate FPS every 30 frames.
        if (gCallCountMarkerDetect % 30 == 0) {
            gFPS = 30.0/arUtilTimer();
            arUtilTimerReset();
            gCallCountMarkerDetect = 0;
        }
		gCallCountMarkerDetect++; // Increment ARToolKit FPS counter.
		

        // Run marker detection on frame
        if (threadHandle) {
            // Perform NFT tracking.
            float            err;
            int              ret;
            int              pageNo;
            
            if( detectedPage == -2 ) {
                trackingInitStart( threadHandle, gARTImage );
                detectedPage = -1;
            }
            if( detectedPage == -1 ) {
                ret = trackingInitGetResult( threadHandle, trackingTrans, &pageNo);
                if( ret == 1 ) {
                    if (pageNo >= 0 && pageNo < surfaceSetCount) {
                        ARLOGd("Detected page %d.\n", pageNo);
                        detectedPage = pageNo;
                        ar2SetInitTrans(surfaceSet[detectedPage], trackingTrans);
                    } else {
                        ARLOGe("Detected bad page %d.\n", pageNo);
                        detectedPage = -2;
                    }
                } else if( ret < 0 ) {
                    ARLOGd("No page detected.\n");
                    detectedPage = -2;
                }
            }
            if( detectedPage >= 0 && detectedPage < surfaceSetCount) {
                if( ar2Tracking(ar2Handle, surfaceSet[detectedPage], gARTImage, trackingTrans, &err) < 0 ) {
                    ARLOGd("Tracking lost.\n");
                    detectedPage = -2;
                } else {
                    ARLOGd("Tracked page %d (max %d).\n", detectedPage, surfaceSetCount - 1);
                }
            }
        } else {
            ARLOGe("Error: threadHandle\n");
            detectedPage = -2;
        }
        
        // Update markers.
        for (i = 0; i < markersNFTCount; i++) {
            markersNFT[i].validPrev = markersNFT[i].valid;
            if (markersNFT[i].pageNo >= 0 && markersNFT[i].pageNo == detectedPage) {
                markersNFT[i].valid = TRUE;
                for (j = 0; j < 3; j++) for (k = 0; k < 4; k++) markersNFT[i].trans[j][k] = trackingTrans[j][k];
            }
            else markersNFT[i].valid = FALSE;
            if (markersNFT[i].valid) {
                
                // Filter the pose estimate.
                if (markersNFT[i].ftmi) {
                    if (arFilterTransMat(markersNFT[i].ftmi, markersNFT[i].trans, !markersNFT[i].validPrev) < 0) {
                        ARLOGe("arFilterTransMat error with marker %d.\n", i);
                    }
                }
                
                if (!markersNFT[i].validPrev) {
                    // Marker has become visible, tell any dependent objects.
                    VirtualEnvironmentHandleARMarkerAppeared(i);
                }
                
                // We have a new pose, so set that.
                arglCameraViewRH(markersNFT[i].trans, markersNFT[i].pose.T, VIEW_SCALEFACTOR);
                // Tell any dependent objects about the update.
                VirtualEnvironmentHandleARMarkerWasUpdated(i, markersNFT[i].pose);
                
            } else {
                
                if (markersNFT[i].validPrev) {
                    // Marker has ceased to be visible, tell any dependent objects.
                    VirtualEnvironmentHandleARMarkerDisappeared(i);
                }
            }                    
        }

		// Tell GLUT the display has changed.
		glutPostRedisplay();
	} else {
		arUtilSleep(2);
	}
    
}
Ejemplo n.º 17
0
int main(int argc, char** argv)
{
	int i;
	char glutGamemode[32];
	const char *cparam_name = 
		"Data/camera_para.dat";
#ifdef _WIN32
	char			*vconf = "Data\\WDM_camera_flipV.xml";
#else
	char			*vconf = "";
#endif
	char objectDataFilename[] = "Data/object_data_vrml";
	
	// ----------------------------------------------------------------------------
	// Library inits.
	//

	glutInit(&argc, argv);

	// ----------------------------------------------------------------------------
	// Hardware setup.
	//

	if (!setupCamera(cparam_name, vconf, &gARTCparam)) {
		fprintf(stderr, "main(): Unable to set up AR camera.\n");
		exit(-1);
	}
	
#ifdef _WIN32
	CoInitialize(NULL);
#endif

	// ----------------------------------------------------------------------------
	// Library setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	if (!prefWindowed) {
		if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
		else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth);
		glutGameModeString(glutGamemode);
		glutEnterGameMode();
	} else {
		glutInitWindowSize(gARTCparam.xsize, gARTCparam.ysize);
		glutCreateWindow(argv[0]);
	}

	// Setup argl library for current context.
	if ((gArglSettings = arglSetupForCurrentContext()) == NULL) {
		fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n");
		exit(-1);
	}
	debugReportMode();
	arUtilTimerReset();

	if (!setupMarkersObjects(objectDataFilename)) {
		fprintf(stderr, "main(): Unable to set up AR objects and markers.\n");
		Quit();
	}
	
	// Test render all the VRML objects.
    fprintf(stdout, "Pre-rendering the VRML objects...");
	fflush(stdout);
    glEnable(GL_TEXTURE_2D);
    for (i = 0; i < gObjectDataCount; i++) {
		arVrmlDraw(gObjectData[i].vrml_id);
    }
    glDisable(GL_TEXTURE_2D);
	fprintf(stdout, " done\n");
	
	// Register GLUT event-handling callbacks.
	// NB: Idle() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Ejemplo n.º 18
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;
	int				i;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    arVideoCapNext();

    /* check for object visibility */
   	for( i = 0; i < PTT_NUM; i++){
		k = -1;
	    for( j = 0; j < marker_num; j++ ) {
	        if( object[i].patt_id == marker_info[j].id ) {
	            if( k == -1 ) k = j;
	            else if( marker_info[k].cf < marker_info[j].cf ) k = j;
	        }	
	    }
		if( k == -1 ) { /* not find marker */
			object[i].visible = 0;
			isFirst[i] = 1;
		}
		else{
			/* get the transformation between the marker and the real camera */
			if( isFirst[i]){
				arGetTransMat(&marker_info[k], object[i].patt_center, object[i].patt_width, object[i].patt_trans);
			}else{
				arGetTransMatCont(&marker_info[k], object[i].patt_trans, object[i].patt_center, object[i].patt_width, object[i].patt_trans);
			}
			object[i].visible = 1;
			isFirst[i] = 0;
			
			/* 追加 */
			if(i == PTT2_MARK_ID){
				arUtilMatInv( object[PTT2_MARK_ID].patt_trans, itrans2); // 逆行列の計算
			}
		}
	}

	//Initialize(); // fix me
	draw();

	argSwapBuffers();
}
Ejemplo n.º 19
0
int main(int argc, char** argv)
{
	char    glutGamemode[32] = "";
    char   *vconf = NULL;
    char    cparaDefault[] = "Data2/camera_para.dat";
    char   *cpara = NULL;
    int     i;
    int     gotTwoPartOption;
    const char markerConfigDataFilename[] = "Data2/markers.dat";
	const char objectDataFilename[] = "Data2/objects.dat";
	
#ifdef DEBUG
    arLogLevel = AR_LOG_LEVEL_DEBUG;
#endif
    
    //
	// Process command-line options.
	//
    
	glutInit(&argc, argv);
    
    i = 1; // argv[0] is name of app, so start at 1.
    while (i < argc) {
        gotTwoPartOption = FALSE;
        // Look for two-part options first.
        if ((i + 1) < argc) {
            if (strcmp(argv[i], "--vconf") == 0) {
                i++;
                vconf = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--cpara") == 0) {
                i++;
                cpara = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--width") == 0) {
                i++;
                // Get width from second field.
                if (sscanf(argv[i], "%d", &prefWidth) != 1) {
                    ARLOGe("Error: --width option must be followed by desired width.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--height") == 0) {
                i++;
                // Get height from second field.
                if (sscanf(argv[i], "%d", &prefHeight) != 1) {
                    ARLOGe("Error: --height option must be followed by desired height.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--refresh") == 0) {
                i++;
                // Get refresh rate from second field.
                if (sscanf(argv[i], "%d", &prefRefresh) != 1) {
                    ARLOGe("Error: --refresh option must be followed by desired refresh rate.\n");
                }
                gotTwoPartOption = TRUE;
            }
        }
        if (!gotTwoPartOption) {
            // Look for single-part options.
            if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
                usage(argv[0]);
            } else if (strncmp(argv[i], "-cpara=", 7) == 0) {
                cpara = &(argv[i][7]);
            } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) {
                ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING);
                exit(0);
            } else if (strcmp(argv[i],"--windowed") == 0) {
                prefWindowed = TRUE;
            } else if (strcmp(argv[i],"--fullscreen") == 0) {
                prefWindowed = FALSE;
            } else {
                ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                usage(argv[0]);
            }
        }
        i++;
    }
    

	//
	// Video setup.
	//
    
	if (!setupCamera((cpara ? cpara : cparaDefault), vconf, &gCparamLT)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

    //
    // AR init.
    //
    
    if (!initNFT(gCparamLT, arVideoGetPixelFormat())) {
		ARLOGe("main(): Unable to init NFT.\n");
		exit(-1);
    }

    //
    // Markers setup.
    //
    
    // Load marker(s).
    newMarkers(markerConfigDataFilename, &markersNFT, &markersNFTCount);
    if (!markersNFTCount) {
        ARLOGe("Error loading markers from config. file '%s'.\n", markerConfigDataFilename);
		cleanup();
		exit(-1);
    }
    ARLOGi("Marker count = %d\n", markersNFTCount);
    
    // Marker data has been loaded, so now load NFT data.
    if (!loadNFTData()) {
        ARLOGe("Error loading NFT data.\n");
		cleanup();
		exit(-1);
    }
	
	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (prefWindowed) {
        if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
        else glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize);
        glutCreateWindow(argv[0]);
    } else {
        if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
            if (prefWidth && prefHeight) {
                if (prefDepth) {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i", prefWidth, prefHeight, prefDepth);
                } else {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i@%i", prefWidth, prefHeight, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
                }
            } else {
                prefWidth = glutGameModeGet(GLUT_GAME_MODE_WIDTH);
                prefHeight = glutGameModeGet(GLUT_GAME_MODE_HEIGHT);
                snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
            }
            glutGameModeString(glutGamemode);
            glutEnterGameMode();
        } else {
            if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
            glutCreateWindow(argv[0]);
            glutFullScreen();
        }
    }
    
    // Create the OpenGL projection from the calibrated camera parameters.
    arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens);
    cameraPoseValid = FALSE;
    
	// Setup ARgsub_lite library for current OpenGL context.
	if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
		ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
		cleanup();
		exit(-1);
	}
    
    // Load objects (i.e. OSG models).
    VirtualEnvironmentInit(objectDataFilename);
    VirtualEnvironmentHandleARViewUpdatedCameraLens(cameraLens);
    
    //
    // Setup complete. Start tracking.
    //
    
    // Start the video.
    if (arVideoCapStart() != 0) {
    	ARLOGe("setupCamera(): Unable to begin camera data capture.\n");
		return (FALSE);
	}
	arUtilTimerReset();
	
	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Ejemplo n.º 20
0
int main(int argc, char** argv)
{
    char glutGamemode[32];
    char *cparam_name = "Data/camera_para.dat";
    char *vconf = "";
    char *patt_name  = "Data/patt.hiro";

    // ----------------------------------------------------------------------------
    // Library inits.
    //

    glutInit(&argc, argv);

    // ----------------------------------------------------------------------------
    // Hardware setup.
    //

    if (!setupCamera(cparam_name, vconf, &gARTCparam)) {
        fprintf(stderr, "main(): Unable to set up AR camera.\n");
        exit(-1);
    }

    // ----------------------------------------------------------------------------
    // Library setup.
    //

    // Set up GL context(s) for OpenGL to draw into.
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (!prefWindowed) {
        if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
        else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth);
        glutGameModeString(glutGamemode);
        glutEnterGameMode();
    } else {
        glutInitWindowSize(prefWidth, prefHeight);
        glutCreateWindow(argv[0]);
    }

    //	// Setup ARgsub_lite library for current OpenGL context.
    //	if ((gArglSettings = arglSetupForCurrentContext()) == NULL) {
    //		fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n");
    //		cleanup();
    //		exit(-1);
    //	}
    //	debugReportMode(gArglSettings);
    glEnable(GL_DEPTH_TEST);
    arUtilTimerReset();

    // Load marker(s).
    if (!setupMarker(patt_name, &gPatt_id)) {
        fprintf(stderr, "main(): Unable to set up AR marker.\n");
        cleanup();
        exit(-1);
    }

    //	// Register GLUT event-handling callbacks.
    //	// NB: mainLoop() is registered by Visibility.
    //	glutDisplayFunc(Display);
    //	glutReshapeFunc(Reshape);
    //	glutVisibilityFunc(Visibility);
    //	glutKeyboardFunc(Keyboard);

    //	glutMainLoop();

    return (0);
}
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             i, j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }
    arVideoCapNext();

    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );
    glClear(GL_DEPTH_BUFFER_BIT);

    /* check for object visibility */
    for( i = 0; i < 2; i++ ) {
        k = -1;
        for( j = 0; j < marker_num; j++ ) {
            if( object[i].patt_id == marker_info[j].id ) {
                if( k == -1 ) k = j;
                else if( marker_info[k].cf < marker_info[j].cf ) k = j;
            }
        }
        object[i].visible = k;

        if( k >= 0 ) {
            arGetTransMat(&marker_info[k],
                          object[i].center, object[i].width,
                          object[i].trans);
            draw( object[i].model_id, object[i].trans );
        }
    }
    argSwapBuffers();

    if( object[0].visible >= 0
     && object[1].visible >= 0 ) {
        double  wmat1[3][4], wmat2[3][4];

        arUtilMatInv(object[0].trans, wmat1);
        arUtilMatMul(wmat1, object[1].trans, wmat2);

        for( j = 0; j < 3; j++ ) {
            for( i = 0; i < 4; i++ ) printf("%8.4f ", wmat2[j][i]);
            printf("\n");
        }
        printf("\n\n");
    }
}
Ejemplo n.º 22
0
static void mainLoop(void)
{
    AR2VideoBufferT *buff;
    ARMarkerInfo   *markerInfo;
    int             markerNum;
    ARdouble        patt_trans[3][4];
    ARdouble        err;
    int             debugMode;
    int             j, k;

    /* grab a video frame */
    buff = arVideoGetImage();
    if (!buff || !buff->fillFlag) {
        arUtilSleep(2);
        return;
    }

    /* detect the markers in the video frame */
    if( arDetectMarker(arHandle, buff) < 0 ) {
        cleanup();
        exit(0);
    }

    argSetWindow(w1);
    
    arGetDebugMode(arHandle, &debugMode);
    if (debugMode == AR_DEBUG_ENABLE) {
        int imageProcMode;
        argViewportSetPixFormat(vp1, AR_PIXEL_FORMAT_MONO); // Drawing the debug image.
        argDrawMode2D(vp1);
        arGetImageProcMode(arHandle, &imageProcMode);
        if (imageProcMode == AR_IMAGE_PROC_FRAME_IMAGE) argDrawImage(arHandle->labelInfo.bwImage);
        else argDrawImageHalf(arHandle->labelInfo.bwImage);
    } else {
        AR_PIXEL_FORMAT pixFormat;
        arGetPixelFormat(arHandle, &pixFormat);
        argViewportSetPixFormat(vp1, pixFormat); // Drawing the input image.
        argDrawMode2D(vp1);
        argDrawImage(buff->buff);
    }

    argSetWindow(w2);
    argDrawMode2D(vp2);
    argDrawImage(buff->buff);
    argSetWindow(w1);

    if( count % 10 == 0 ) {
        sprintf(fps, "%f[fps]", 10.0/arUtilTimer());
        arUtilTimerReset();
    }
    count++;
    glColor3f(0.0f, 1.0f, 0.0f);
    argDrawStringsByIdealPos(fps, 10, ysize-30);

    markerNum = arGetMarkerNum( arHandle );
    if( markerNum == 0 ) {
        argSetWindow(w1);
        argSwapBuffers();
        argSetWindow(w2);
        argSwapBuffers();
        return;
    }

    /* check for object visibility */
    markerInfo =  arGetMarker( arHandle ); 
    k = -1;
    for( j = 0; j < markerNum; j++ ) {
        //ARLOG("ID=%d, CF = %f\n", markerInfo[j].id, markerInfo[j].cf);
        if( patt_id == markerInfo[j].id ) {
            if( k == -1 ) {
                if (markerInfo[j].cf > 0.7) k = j;
            } else if (markerInfo[j].cf > markerInfo[k].cf) k = j;
        }
    }
    if( k == -1 ) {
        argSetWindow(w1);
        argSwapBuffers();
        argSetWindow(w2);
        argSwapBuffers();
        return;
    }

    err = arGetTransMatSquare(ar3DHandle, &(markerInfo[k]), patt_width, patt_trans);
    sprintf(errValue, "err = %f", err);
    glColor3f(0.0f, 1.0f, 0.0f);
    argDrawStringsByIdealPos(fps, 10, ysize-30);
    argDrawStringsByIdealPos(errValue, 10, ysize-60);
    //ARLOG("err = %f\n", err);

    draw(patt_trans);

    argSetWindow(w1);
    argSwapBuffers();
    argSetWindow(w2);
    argSwapBuffers();
}
Ejemplo n.º 23
0
int main(int argc, char** argv)
{
	char    glutGamemode[32] = "";
    char   *vconf = NULL;
    char    cparaDefault[] = "../share/artoolkit-examples/Data/camera_para.dat";
    char   *cpara = NULL;
    int     i;
    int     gotTwoPartOption;
    const char markerConfigDataFilename[] = "../share/artoolkit-examples/Data/markers.dat";
	const char objectDataFilename[] = "../share/artoolkit-examples/Data/objects.dat";
    //
	// Process command-line options.
	//
    
	glutInit(&argc, argv);
    
    i = 1; // argv[0] is name of app, so start at 1.
    while (i < argc) {
        gotTwoPartOption = FALSE;
        // Look for two-part options first.
        if ((i + 1) < argc) {
            if (strcmp(argv[i], "--vconf") == 0) {
                i++;
                vconf = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--cpara") == 0) {
                i++;
                cpara = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--width") == 0) {
                i++;
                // Get width from second field.
                if (sscanf(argv[i], "%d", &prefWidth) != 1) {
                    ARLOGe("Error: --width option must be followed by desired width.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--height") == 0) {
                i++;
                // Get height from second field.
                if (sscanf(argv[i], "%d", &prefHeight) != 1) {
                    ARLOGe("Error: --height option must be followed by desired height.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--refresh") == 0) {
                i++;
                // Get refresh rate from second field.
                if (sscanf(argv[i], "%d", &prefRefresh) != 1) {
                    ARLOGe("Error: --refresh option must be followed by desired refresh rate.\n");
                }
                gotTwoPartOption = TRUE;
            }
        }
        if (!gotTwoPartOption) {
            // Look for single-part options.
            if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
                usage(argv[0]);
            } else if (strncmp(argv[i], "-cpara=", 7) == 0) {
                cpara = &(argv[i][7]);
            } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) {
                ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING);
                exit(0);
            } else if (strcmp(argv[i],"--windowed") == 0) {
                prefWindowed = TRUE;
            } else if (strcmp(argv[i],"--fullscreen") == 0) {
                prefWindowed = FALSE;
            } else {
                ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                usage(argv[0]);
            }
        }
        i++;
    }
    

	//
	// Video setup.
	//
    
	if (!setupCamera((cpara ? cpara : cparaDefault), vconf, &gCparamLT)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

    //
    // AR init.
    //
    
    // Init AR.
    gARPattHandle = arPattCreateHandle();
	if (!gARPattHandle) {
		ARLOGe("Error creating pattern handle.\n");
		exit(-1);
	}
    
    gARHandle = arCreateHandle(gCparamLT);
    if (!gARHandle) {
        ARLOGe("Error creating AR handle.\n");
		exit(-1);
    }
    arPattAttach(gARHandle, gARPattHandle);
    
    if (arSetPixelFormat(gARHandle, arVideoGetPixelFormat()) < 0) {
        ARLOGe("Error setting pixel format.\n");
		exit(-1);
    }
    
    gAR3DHandle = ar3DCreateHandle(&gCparamLT->param);
    if (!gAR3DHandle) {
        ARLOGe("Error creating 3D handle.\n");
		exit(-1);
    }
            
    //
    // Markers setup.
    //
    
    // Load marker(s).
    newMarkers(markerConfigDataFilename, gARPattHandle, &markersSquare, &markersSquareCount, &gARPattDetectionMode);
    ARLOGi("Marker count = %d\n", markersSquareCount);
    
    //
    // Other ARToolKit setup.
    //
    
    arSetMarkerExtractionMode(gARHandle, AR_USE_TRACKING_HISTORY_V2);
    //arSetMarkerExtractionMode(gARHandle, AR_NOUSE_TRACKING_HISTORY);
    //arSetLabelingThreshMode(gARHandle, AR_LABELING_THRESH_MODE_MANUAL); // Uncomment to force manual thresholding.
    
    // Set the pattern detection mode (template (pictorial) vs. matrix (barcode) based on
    // the marker types as defined in the marker config. file.
    arSetPatternDetectionMode(gARHandle, gARPattDetectionMode); // Default = AR_TEMPLATE_MATCHING_COLOR
    
    // Other application-wide marker options. Once set, these apply to all markers in use in the application.
    // If you are using standard ARToolKit picture (template) markers, leave commented to use the defaults.
    // If you are usign a different marker design (see http://www.artoolworks.com/support/app/marker.php )
    // then uncomment and edit as instructed by the marker design application.
    //arSetLabelingMode(gARHandle, AR_LABELING_BLACK_REGION); // Default = AR_LABELING_BLACK_REGION
    //arSetBorderSize(gARHandle, 0.25f); // Default = 0.25f
    //arSetMatrixCodeType(gARHandle, AR_MATRIX_CODE_3x3); // Default = AR_MATRIX_CODE_3x3
    
	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (prefWindowed) {
        if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
        else glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize);
        glutCreateWindow(argv[0]);
    } else {
        if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
            if (prefWidth && prefHeight) {
                if (prefDepth) {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i", prefWidth, prefHeight, prefDepth);
                } else {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i@%i", prefWidth, prefHeight, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
                }
            } else {
                prefWidth = glutGameModeGet(GLUT_GAME_MODE_WIDTH);
                prefHeight = glutGameModeGet(GLUT_GAME_MODE_HEIGHT);
                snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
            }
            glutGameModeString(glutGamemode);
            glutEnterGameMode();
        } else {
            if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
            glutCreateWindow(argv[0]);
            glutFullScreen();
        }
    }
    
    // Create the OpenGL projection from the calibrated camera parameters.
    arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens);
    cameraPoseValid = FALSE;
    
	// Setup ARgsub_lite library for current OpenGL context.
	if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
		ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
		cleanup();
		exit(-1);
	}
    arglSetupDebugMode(gArglSettings, gARHandle);
    
    // Load objects (i.e. OSG models).
    VirtualEnvironmentInit(objectDataFilename);
    VirtualEnvironmentHandleARViewUpdatedCameraLens(cameraLens);
    
    //
    // Setup complete. Start tracking.
    //
    
    // Start the video.
    if (arVideoCapStart() != 0) {
    	ARLOGe("setupCamera(): Unable to begin camera data capture.\n");
		return (FALSE);
	}
	arUtilTimerReset();
	
	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Ejemplo n.º 24
0
int main(int argc, char** argv)
{
	char glutGamemode[32];
	char cparam_name[] = "Data/camera_para.dat";
	char vconf[] = "";
	char patt_name[]  = "Data/patt.hiro";
    
    char movieFileName[] = "Data/sample.mov";
    char *movieURI;
	
    //
	// Library inits.
	//

	glutInit(&argc, argv);

	//
	// Video setup.
	//

	if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	if (!windowed) {
		if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh);
		else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth);
		glutGameModeString(glutGamemode);
		glutEnterGameMode();
	} else {
		glutInitWindowSize(windowWidth, windowHeight);
		glutCreateWindow(argv[0]);
	}

	// Setup ARgsub_lite library for current OpenGL context.
	if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
		ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
		cleanup();
		exit(-1);
	}
    arglSetupDebugMode(gArglSettings, gARHandle);
	arUtilTimerReset();
		
	// Load marker(s).
	if (!setupMarker(patt_name, &gPatt_id, gARHandle, &gARPattHandle)) {
		ARLOGe("main(): Unable to set up AR marker.\n");
		cleanup();
		exit(-1);
	}
	
    //
    // Movie loading.
    //

    // In this example, we load a movie via a file URI, but other URIs allowed
    // by the QuickTime module would also be fine.

    // Movie relative path is in "movieFileName". Get a file:// URI for it.
    movieURI = arUtilGetFileURI(movieFileName);
    if (!movieURI) {
        ARLOGe("Error: Unable to construct URI for movie file '%s'.\n", movieFileName);
		cleanup();
		exit(-1);
    }
    
    // Now open the movie.
    if (!setupMovie(movieURI)) {
        ARLOGe("Error: Unable to open movie at URI '%s'.\n", movieURI);
        free(movieURI);
		cleanup();
		exit(-1);
    }
    
    free(movieURI); // We're finished with movieURI, so free it.

	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Ejemplo n.º 25
0
int main(int argc, char **argv)
{
    char                glutGamemode[32];
    char                *cpara                                 = NULL;
    char                cparaDefault[]                         = "Data/camera_para.dat";
    char                *vconf                                 = NULL;
    int                 patt_names_count                       = 0;
    char                *patt_names[CHECK_ID_MULTIMARKERS_MAX] = {NULL};
    ARdouble            pattRatio                              = (ARdouble)AR_PATT_RATIO;
    AR_MATRIX_CODE_TYPE matrixCodeType                         = AR_MATRIX_CODE_TYPE_DEFAULT;
    int                 labelingMode                           = AR_DEFAULT_LABELING_MODE;
    int                 patternDetectionMode                   = AR_DEFAULT_PATTERN_DETECTION_MODE;
    int                 i, gotTwoPartOption;
    float               tempF;
    int                 tempI;


    //
    // Library inits.
    //

    glutInit(&argc, argv);

    //
    // Startup options.
    //

    i = 1; // argv[0] is name of app, so start at 1.

    while (i < argc)
    {
        gotTwoPartOption = FALSE;
        // Look for two-part options first.
        if ((i + 1) < argc)
        {
            if (strcmp(argv[i], "--vconf") == 0)
            {
                i++;
                vconf            = argv[i];
                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--cpara") == 0)
            {
                i++;
                cpara            = argv[i];
                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--pattRatio") == 0)
            {
                i++;
                if (sscanf(argv[i], "%f", &tempF) == 1 && tempF > 0.0f && tempF < 1.0f)
                    pattRatio = (ARdouble)tempF;
                else
                    ARLOGe("Error: argument '%s' to --pattRatio invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--pattSize") == 0)
            {
                i++;
                if (sscanf(argv[i], "%d", &tempI) == 1 && tempI >= 16 && tempI <= AR_PATT_SIZE1_MAX)
                    gPattSize = tempI;
                else
                    ARLOGe("Error: argument '%s' to --pattSize invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--pattCountMax") == 0)
            {
                i++;
                if (sscanf(argv[i], "%d", &tempI) == 1 && tempI > 0)
                    gPattCountMax = tempI;
                else
                    ARLOGe("Error: argument '%s' to --pattSize invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--borderSize") == 0)
            {
                i++;
                if (sscanf(argv[i], "%f", &tempF) == 1 && tempF > 0.0f && tempF < 0.5f)
                    pattRatio = (ARdouble)(1.0f - 2.0f * tempF);
                else
                    ARLOGe("Error: argument '%s' to --borderSize invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--matrixCodeType") == 0)
            {
                i++;
                if (strcmp(argv[i], "AR_MATRIX_CODE_3x3") == 0)
                    matrixCodeType = AR_MATRIX_CODE_3x3;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_3x3_HAMMING63") == 0)
                    matrixCodeType = AR_MATRIX_CODE_3x3_HAMMING63;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_3x3_PARITY65") == 0)
                    matrixCodeType = AR_MATRIX_CODE_3x3_PARITY65;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4") == 0)
                    matrixCodeType = AR_MATRIX_CODE_4x4;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4_BCH_13_9_3") == 0)
                    matrixCodeType = AR_MATRIX_CODE_4x4_BCH_13_9_3;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4_BCH_13_5_5") == 0)
                    matrixCodeType = AR_MATRIX_CODE_4x4_BCH_13_5_5;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_5x5") == 0)
                    matrixCodeType = AR_MATRIX_CODE_5x5;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_6x6") == 0)
                    matrixCodeType = AR_MATRIX_CODE_6x6;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_GLOBAL_ID") == 0)
                    matrixCodeType = AR_MATRIX_CODE_GLOBAL_ID;
                else
                    ARLOGe("Error: argument '%s' to --matrixCodeType invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--labelingMode") == 0)
            {
                i++;
                if (strcmp(argv[i], "AR_LABELING_BLACK_REGION") == 0)
                    labelingMode = AR_LABELING_BLACK_REGION;
                else if (strcmp(argv[i], "AR_LABELING_WHITE_REGION") == 0)
                    labelingMode = AR_LABELING_WHITE_REGION;
                else
                    ARLOGe("Error: argument '%s' to --labelingMode invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--patternDetectionMode") == 0)
            {
                i++;
                if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_COLOR") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_COLOR;
                else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_MONO") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_MONO;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_DETECTION") == 0)
                    patternDetectionMode = AR_MATRIX_CODE_DETECTION;
                else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX;
                else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_MONO_AND_MATRIX") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_MONO_AND_MATRIX;
                else
                    ARLOGe("Error: argument '%s' to --patternDetectionMode invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
        }

        if (!gotTwoPartOption)
        {
            // Look for single-part options.
            if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0)
            {
                usage(argv[0]);
            }
            else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0)
            {
                ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING);
                exit(0);
            }
            else if (strncmp(argv[i], "-border=", 8) == 0)
            {
                if (sscanf(&(argv[i][8]), "%f", &tempF) == 1 && tempF > 0.0f && tempF < 0.5f)
                    pattRatio = (ARdouble)(1.0f - 2.0f * tempF);
                else
                    ARLOGe("Error: argument '%s' to -border= invalid.\n", argv[i]);
            }
            else
            {
                if (patt_names_count < CHECK_ID_MULTIMARKERS_MAX)
                {
                    patt_names[patt_names_count] = argv[i];
                    patt_names_count++;
                }

                // } else {
                //    ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                //    usage(argv[0]);
            }
        }

        i++;
    }

    //
    // Video setup.
    //

    if (!cpara)
        cpara = cparaDefault;

    if (!setupCamera(cpara, vconf, &gCparamLT, &gARHandle, &gAR3DHandle))
    {
        ARLOGe("main(): Unable to set up AR camera.\n");
        exit(-1);
    }

    //
    // AR init.
    //

    arSetPatternDetectionMode(gARHandle, patternDetectionMode);
    arSetLabelingMode(gARHandle, labelingMode);
    arSetPattRatio(gARHandle, pattRatio);
    arSetMatrixCodeType(gARHandle, matrixCodeType);

    //
    // Graphics setup.
    //

    // Set up GL context(s) for OpenGL to draw into.
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (!windowed)
    {
        if (windowRefresh)
            sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh);
        else
            sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth);

        glutGameModeString(glutGamemode);
        glutEnterGameMode();
    }
    else
    {
        glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize);
        glutCreateWindow(argv[0]);
    }

    // Setup ARgsub_lite library for current OpenGL context.
    if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL)
    {
        ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
        cleanup();
        exit(-1);
    }

    arglSetupDebugMode(gArglSettings, gARHandle);
    arUtilTimerReset();

    // Load marker(s).
    if (!setupMarkers(patt_names_count, (const char**)patt_names, gMultiConfigs, gARHandle, &gARPattHandle))
    {
        ARLOGe("main(): Unable to set up AR marker(s).\n");
        cleanup();
        exit(-1);
    }

    gMultiConfigCount = patt_names_count;

    // Register GLUT event-handling callbacks.
    // NB: mainLoop() is registered by Visibility.
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    glutVisibilityFunc(Visibility);
    glutKeyboardFunc(Keyboard);

    glutMainLoop();

    return (0);
}
Ejemplo n.º 26
0
int main(int argc, char** argv)
{
    int i;
    char glutGamemode[32];
    char cparam_name[] = "Data/camera_para.dat";
    char vconf[] = "";
    char objectDataFilename[] = "Data/object_data_vrml";

    //
    // Library inits.
    //

    glutInit(&argc, argv);

    //
    // Video setup.
    //

    if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) {
        ARLOGe("main(): Unable to set up AR camera.\n");
        exit(-1);
    }

#ifdef _WIN32
    CoInitialize(NULL);
#endif

    //
    // Graphics setup.
    //

    // Set up GL context(s) for OpenGL to draw into.
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (!windowed) {
        if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh);
        else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth);
        glutGameModeString(glutGamemode);
        glutEnterGameMode();
    } else {
        glutInitWindowSize(windowWidth, windowHeight);
        glutCreateWindow(argv[0]);
    }

    // Setup ARgsub_lite library for current OpenGL context.
    if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
        ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
        cleanup();
        exit(-1);
    }
    arglSetupDebugMode(gArglSettings, gARHandle);
    arUtilTimerReset();

    if (!setupMarkersObjects(objectDataFilename, &gObjectData, &gObjectDataCount, gARHandle)) {
        ARLOGe("main(): Unable to set up AR objects and markers.\n");
        cleanup();
        exit(-1);
    }

    // Test render all the VRML objects.
    ARLOGi("Pre-rendering the VRML objects...\n");
    glEnable(GL_TEXTURE_2D);
    for (i = 0; i < gObjectDataCount; i++) {
        arVrmlDraw(gObjectData[i].vrml_id);
    }
    glDisable(GL_TEXTURE_2D);
    ARLOGi("  done\n");

    // Register GLUT event-handling callbacks.
    // NB: mainLoop() is registered by Visibility.
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    glutVisibilityFunc(Visibility);
    glutKeyboardFunc(Keyboard);

    glutMainLoop();

    return (0);
}
Ejemplo n.º 27
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             i,j,k;

    /* grab a video frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }

    if( count == 0 ) arUtilTimerReset();
    count++;

    /*draw the video*/
    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* capture the next video frame */
    arVideoCapNext();

    glColor3f( 1.0, 0.0, 0.0 );
    glLineWidth(6.0);

    /* detect the markers in the video frame */
    if(arDetectMarker(dataPtr, thresh,
                      &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }
    for( i = 0; i < marker_num; i++ ) {
        argDrawSquare(marker_info[i].vertex,0,0);
    }

    /* check for known patterns */
    for( i = 0; i < objectnum; i++ ) {
        k = -1;
        for( j = 0; j < marker_num; j++ ) {
            if( object[i].id == marker_info[j].id) {

                /* you've found a pattern */
                //printf("Found pattern: %d ",patt_id);
                glColor3f( 0.0, 1.0, 0.0 );
                argDrawSquare(marker_info[j].vertex,0,0);

                if( k == -1 ) k = j;
                else /* make sure you have the best pattern (highest confidence factor) */
                    if( marker_info[k].cf < marker_info[j].cf ) k = j;
            }
        }
        if( k == -1 ) {
            object[i].visible = 0;
            continue;
        }

        /* calculate the transform for each marker */
        if( object[i].visible == 0 ) {
            arGetTransMat(&marker_info[k],
                          object[i].marker_center, object[i].marker_width,
                          object[i].trans);
        }
        else {
            arGetTransMatCont(&marker_info[k], object[i].trans,
                              object[i].marker_center, object[i].marker_width,
                              object[i].trans);
        }
        object[i].visible = 1;
    }

    /*check for object collisions between marker 0 and 1 */
    if(object[0].visible && object[1].visible) {
        if(checkCollisions(object[0],object[1],COLLIDE_DIST)) {
            object[0].collide = 1;
            object[1].collide = 1;
        }
        else {
            object[0].collide = 0;
            object[1].collide = 0;
        }
    }

    /* draw the AR graphics */
    draw( object, objectnum );

    /*swap the graphics buffers*/
    argSwapBuffers();
}
Ejemplo n.º 28
0
static void Keyboard(unsigned char key, int x, int y)
{
	int mode, threshChange = 0;
	
	switch (key) {
		case 0x1B:						// Quit.
		case 'Q':
		case 'q':
			cleanup();
			exit(0);
			break;
		case ' ':
			gDrawRotate = !gDrawRotate;
			break;
		case 'C':
		case 'c':
			ARLOGe("*** Camera - %f (frame/sec)\n", (double)gCallCountMarkerDetect/arUtilTimer());
			gCallCountMarkerDetect = 0;
			arUtilTimerReset();
			debugReportMode(gARHandle);
			break;
		case '-':
			threshChange = -5;
			break;
		case '+':
		case '=':
			threshChange = +5;
			break;
		case 'D':
		case 'd':
			arGetDebugMode(gARHandle, &mode);
			arSetDebugMode(gARHandle, !mode);
			break;
        case 'B':
        case 'b':
            arGetLabelingMode(gARHandle, &mode);
            if (mode == AR_LABELING_BLACK_REGION) arSetLabelingMode(gARHandle, AR_LABELING_WHITE_REGION);
            else arSetLabelingMode(gARHandle, AR_LABELING_BLACK_REGION);
			break;
        case '?':
		case '/':
			ARLOG("Keys:\n");
			ARLOG(" q or [esc]    Quit demo.\n");
			ARLOG(" c             Calulcate frame rate.\n");
			ARLOG(" - and +       Adjust threshhold.\n");
			ARLOG(" d             Activate / deactivate debug mode.\n");
			ARLOG(" b             Toggle between detection of black markers and white markers.\n");
			ARLOG(" ? or /        Show this help.\n");
			ARLOG("\nAdditionally, the ARVideo library supplied the following help text:\n");
			arVideoDispOption();
			break;
		default:
			break;
	}
	if (threshChange) {
		int threshhold;
		arGetLabelingThresh(gARHandle, &threshhold);
		threshhold += threshChange;
		if (threshhold < 0) threshhold = 0;
		if (threshhold > 255) threshhold = 255;
		arSetLabelingThresh(gARHandle, threshhold);
		ARLOG("Threshhold changed to %d.\n", threshhold);
	}
	
}
Ejemplo n.º 29
0
static void Keyboard(unsigned char key, int x, int y)
{
	int mode, threshChange = 0;
    AR_LABELING_THRESH_MODE modea;
	
	switch (key) {
		case 0x1B:						// Quit.
		case 'Q':
		case 'q':
			cleanup();
			exit(0);
			break;
		case 'X':
		case 'x':
            arGetImageProcMode(gARHandle, &mode);
            switch (mode) {
                case AR_IMAGE_PROC_FRAME_IMAGE:  mode = AR_IMAGE_PROC_FIELD_IMAGE; break;
                case AR_IMAGE_PROC_FIELD_IMAGE:
                default: mode = AR_IMAGE_PROC_FRAME_IMAGE; break;
            }
            arSetImageProcMode(gARHandle, mode);
			break;
		case 'C':
		case 'c':
			ARLOGe("*** Camera - %f (frame/sec)\n", (double)gCallCountMarkerDetect/arUtilTimer());
			gCallCountMarkerDetect = 0;
			arUtilTimerReset();
			break;
		case 'a':
		case 'A':
			arGetLabelingThreshMode(gARHandle, &modea);
            switch (modea) {
                case AR_LABELING_THRESH_MODE_MANUAL:        modea = AR_LABELING_THRESH_MODE_AUTO_MEDIAN; break;
                case AR_LABELING_THRESH_MODE_AUTO_MEDIAN:   modea = AR_LABELING_THRESH_MODE_AUTO_OTSU; break;
                case AR_LABELING_THRESH_MODE_AUTO_OTSU:     modea = AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE; break;
                case AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE: modea = AR_LABELING_THRESH_MODE_AUTO_BRACKETING; break;
                case AR_LABELING_THRESH_MODE_AUTO_BRACKETING:
                default: modea = AR_LABELING_THRESH_MODE_MANUAL; break;
            }
            arSetLabelingThreshMode(gARHandle, modea);
			break;
		case '-':
			threshChange = -5;
			break;
		case '+':
		case '=':
			threshChange = +5;
			break;
		case 'D':
		case 'd':
			arGetDebugMode(gARHandle, &mode);
			arSetDebugMode(gARHandle, !mode);
			break;
		case '?':
		case '/':
            gShowHelp++;
            if (gShowHelp > 1) gShowHelp = 0;
			break;
        case 'm':
        case 'M':
            gShowMode = !gShowMode;
            break;
		default:
			break;
	}
	if (threshChange) {
		int threshhold;
		arGetLabelingThresh(gARHandle, &threshhold);
		threshhold += threshChange;
		if (threshhold < 0) threshhold = 0;
		if (threshhold > 255) threshhold = 255;
		arSetLabelingThresh(gARHandle, threshhold);
	}
	
}
Ejemplo n.º 30
0
int main(int argc, char** argv)
{
	char glutGamemode[32];
	const char *cparam_name = "Data/camera_para.dat";
    char vconf[] = "";
	const char *patt_name  = "Data/cubeMarkerConfig.dat";
	
    //
	// Library inits.
	//

	glutInit(&argc, argv);

	//
	// Video setup.
	//

	if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	if (!prefWindowed) {
		if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
		else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth);
		glutGameModeString(glutGamemode);
		glutEnterGameMode();
	} else {
		glutInitWindowSize(prefWidth, prefHeight);
		glutCreateWindow(argv[0]);
	}

	// Setup ARgsub_lite library for current OpenGL context.
	if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
		ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
		cleanup();
		exit(-1);
	}
    arglSetupDebugMode(gArglSettings, gARHandle);
	debugReportMode(gARHandle);
	glEnable(GL_DEPTH_TEST);
	arUtilTimerReset();
		
	// Load marker(s).
	if (!setupCubeMarker(patt_name, &gMultiConfig, gARHandle, &gARPattHandle)) {
		ARLOGe("main(): Unable to set up AR marker.\n");
		cleanup();
		exit(-1);
	}
	
	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}