Exemple #1
0
static void init( void )
{
    ARParam  wparam;
	int i;
	
    /* open the video path */
    if( arVideoOpen( vconf ) < 0 ) exit(0);
    /* find the size of the window */
    if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
    printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);

    /* set the initial camera parameters */
    if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
        printf("Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    printf("*** Camera Parameter ***\n");
    arParamDisp( &cparam );

	for( i=0; i < PTT_NUM; i++){ 
		if( (object[i].patt_id = arLoadPatt(object[i].patt_name)) < 0 ) {
			printf("パターン読み込みに失敗しました!! %s\n", object[i].patt_name);
			exit(0);
		}
	}

    /* open the graphics window */
    argInit( &cparam, 1.0, 0, 0, 0, 0 );

}
Exemple #2
0
	bool SingleTarget::initialise(const std::string& pattFile, double width, double center[2])
	{
		// Check if this target has already been initialised
		if (patt_id >= 0) 
		{
			osg::notify(osg::WARN) << "SingleTarget: Cannot initialise Target. Already initialised." << std::endl;
			return false;
		}

		// Locate the specified pattern file
		std::string actualPattFile = osgDB::findDataFile(pattFile);
		if (!osgDB::fileExists(actualPattFile)) 
		{
			osg::notify(osg::WARN) << "SingleTarget: Cannot find pattern file: " << pattFile << std::endl;
			return false;
		}

		// Attempt to load pattern file
		patt_id = arLoadPatt(actualPattFile.c_str());
		if (patt_id < 0) 
		{
			osg::notify(osg::WARN) << "SingleTarget: Error loading pattern file: " << pattFile << std::endl;
			return false;
		}
		
		patt_width = width;
		patt_center[0] = center[0];
		patt_center[1] = center[1];
		
		setName(pattFile);
		setActive(false);
		_valid = false;

		return true;
	}
	static void init() {
		ARParam  wparam;

		//Open video path, vconf is default camera config
		if (arVideoOpen(vconf) < 0) {
			exit(0);
		}

		//Get size of window
		if (arVideoInqSize(&xsize, &ysize) < 0) {
			exit(0);
		}

		//Set camera paramaters
		if (arParamLoad(cparam_name, 1, &wparam) < 0) {
			printf("Couldn't load camera parameters");
			exit(0);
		}
		arParamChangeSize(&wparam, xsize, ysize, &cparam);
		arInitCparam(&cparam);

		//Load pattern
		if ((patt_id = arLoadPatt(patt_name)) < 0) {
			printf("Failed to load pattern");
			exit(0);
		}

		//Open graphics window
		argInit(&cparam, 1, 0, 0, 0, 0);
	}
Exemple #4
0
static void init( void )
{
    ARParam  wparam;
	
    /* open the video path */
    if( knVideoOpen( vconf ) < 0 ) exit(0);
    /* find the size of the window */
    if( knVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
    printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);

    /* set the initial camera parameters */
    if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
        printf("Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    printf("*** Camera Parameter ***\n");
    arParamDisp( &cparam );

    if( (patt_id=arLoadPatt(patt_name)) < 0 ) {
        printf("pattern load error !!\n");
        exit(0);
    }

    /* open the graphics window */
    argInit( &cparam, 1.0, 0, 0, 0, 0 );
}
static void init( void )
{
	/* Josh */
	ARParam wparam;
	xsize = 1024; //my size of picture
	ysize = 1024;

	//dp = opendir ("./");
	dp = opendir (directory);

	// devil
	ilInit();
	iluInit();

	if (dp == NULL)
	 {
		printf("Image directory could not be opened !!\n");
        exit(0);
	 }

	// get first image for size, then reload directory
	GetNextImage();
	dp = opendir (directory);

	// if over size limit (or possibly not detected) 
	if ((xsize >= 1024) || (ysize >= 1024) || (xsize == FALSE) || (ysize == FALSE))
	 {
		printf("Image size invalid - too big or broken !!\n");
        exit(0);
	 }

/* Josh */





	arParamChangeSize( &wparam, xsize, ysize, &cparam );
	//arVideoInqSize(&xsize, &ysize);
	printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);

    /* set the initial camera parameters */
    if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
        printf("Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    printf("*** Camera Parameter ***\n");
    arParamDisp( &cparam );

    if( (patt_id=arLoadPatt(patt_name)) < 0 ) {
        printf("pattern load error !!\n");
        exit(0);
    }

    /* open the graphics window */
    argInit( &cparam, 1.0, 0, 0, 0, 0 );
}
//=======================================================
// 初期化関数
//=======================================================
void Init(void)
{
	ARParam wparam;		// カメラパラメータ

	// ビデオデバイスの設定
	if( arVideoOpen( vconf_name ) < 0 ){
		printf("ビデオデバイスのエラー\n");
		exit(0);
	}

	// ウィンドウサイズの取得
	if( arVideoInqSize( &xsize, &ysize ) < 0 ) exit(0);
	printf("Image size (x,y) = (%d,$d)\n", xsize, ysize);

	// カメラパラメータの設定
	if( arParamLoad( cparam_name, 1, &wparam ) < 0 ){
		printf("カメラパラメータの読み込みに失敗しました\n");
		exit(0);
	}

	// カメラパラメータのサイズ調整
	arParamChangeSize( &wparam, xsize, ysize, &cparam );
	// カメラパラメータの初期化
	arInitCparam( &cparam );
	printf("*** Camera Parameter ***\n");
	arParamDisp( &cparam );

	// パターンファイルのロード
	for( int i=0; i<MARK_NUM; i++ ){
		if( (marker[i].patt_id = arLoadPatt(marker[i].patt_name)) < 0){
			printf("パターンファイルの読み込みに失敗しました\n");
			printf("%s\n", marker[i].patt_name);
			exit(0);
		}
	}

	// gsubライブラリの初期化
	argInit( &cparam, 1.0, 0, 0, 0, 0 );

	mqoInit(); //メタセコイアの初期化

	// モデルの読み込み

	for(int i=0;i<8;i++){
		if ( (model[i] = mqoCreateModel( mqo_name[i], 1.0 )) == NULL ) {
				printf("モデルの読み込みに失敗しました\n");
			//	return -1;
		}
	}
	if ( (rmodel = mqoCreateModel( mqo_rnm, 1.0 )) == NULL ) {
		printf("モデルの読み込みに失敗しました\n");
		//	return -1;
	}


	// ウィンドウタイトルの設定
	glutSetWindowTitle("PaperPiano");
}
int TrackerSingleMarker::addPattern(const char* nFileName) {
    int patt_id = arLoadPatt(const_cast<char*> (nFileName));

    if (patt_id < 0) {
        LOGE("ARToolKitPlus: error loading pattern");
    }

    return patt_id;
}
Exemple #8
0
ObjectData_T *read_ObjData( char *name, int *objectnum )
{
    FILE          *fp;
    ObjectData_T  *object;
    char           buf[256], buf1[256];
    int            i;

	printf("Opening Data File %s\n",name);

    if( (fp=fopen(name, "r")) == NULL ) {
		printf("Can't find the file - quitting \n");
		return(0);
	}

    get_buff(buf, 256, fp);
    if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}

	printf("About to load %d Models\n",*objectnum);

    object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
    if( object == NULL ) return(0);

    for( i = 0; i < *objectnum; i++ ) {
		object[i].visible = 0;

		get_buff(buf, 256, fp);
        if( sscanf(buf, "%s", object[i].name) != 1 ) {
            fclose(fp); free(object); return(0);
        }

		printf("Read in No.%d \n", i+1);

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%s", buf1) != 1 ) {
          fclose(fp); free(object); return(0);}

        if( (object[i].id = arLoadPatt(buf1)) < 0 )
            {fclose(fp); free(object); return(0);}

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
            fclose(fp); free(object); return(0);
        }

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf %lf", &object[i].marker_center[0],
            &object[i].marker_center[1]) != 2 ) {
            fclose(fp); free(object); return(0);
        }

    }

    fclose(fp);

    return( object );
}
Exemple #9
0
static int setupMarker(const char *patt_name, int *patt_id)
{
    // Loading only 1 pattern in this example.
    if ((*patt_id = arLoadPatt(patt_name)) < 0) {
        fprintf(stderr, "setupMarker(): pattern load error !!\n");
        return 0;
    }

    return 1;
}
Exemple #10
0
static int setupMarker(const char *patt_name, int *patt_id)
{
	
    if((*patt_id = arLoadPatt(patt_name)) < 0) 
	{
        fprintf(stderr, "setupMarker(): pattern load error !!\n");
        return (FALSE);
    }
	
	return (TRUE);
}
Exemple #11
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;


}
Exemple #12
0
//initialisation artoolkit
void arInit()
{
    printf("Debut initialisation AR\n");
	cout << vconf << endl;
    ARParam wparam;

    ///ouverture fenetre de dialogue  de parametrage
    if( arVideoOpen( vconf ) < 0 ) /*exit(0)*/ printf("Connexion a la webcam impossible\n");
    if( arVideoInqSize(&xsize, &ysize) < 0 ) /*exit(0)*/printf("Impossible de recuperer la taille de la video\n");
    printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);

    ///parametrage de la camera via la fentre de dialogue precedente
   if( arParamLoad(cparam_name, 1, &wparam) < 0 )
    {
        printf("Camera parameter load error !!\n");
        //exit(0);
    }
	//changement des param de base par ceux choisi lors de l'affichage de la fenetre de configuration
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    printf("*** Camera Parameter ***\n");
    arParamDisp( &cparam ); ///affichage parametres

    ///fin init camera

    ///debut init marker de detection
    for( int i = 0; i < 2; i++ )
    {
        if( (object[i].patt_id=arLoadPatt(object[i].patt_name)) < 0 )
        {
            printf("pattern load error: %s\n", object[i].patt_name);
            //exit(0);
        }
    }


	argInit( &cparam, 1.0, 0, 0, 0, 0 );
	
	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    printf("Fin initialisation AR\n");
}
Exemple #13
0
int main(int argc, char **argv) 
{
	ARParam cparam;
	ARParam wparam;
	int xsize, ysize;

	printf("test\n");


	
	glutInit(&argc, argv);


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

	}

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

	if (arParamLoad(cparam_name, 1, &wparam) < 0) {
		printf("カメラパラメータの読み込みに失敗しました\n");
		return -1;

	}

	arParamChangeSize(&wparam, xsize, ysize, &cparam);
	arInitCparam(&cparam);

	if ((patt_id = arLoadPatt(patt_name)) < 0) {
		printf("パターンファイルの読み込みに失敗しました\n");
		return -1;
			
	}

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

	arVideoCapStart();

	argMainLoop(MouseEvent, KeyEvent, MainLoop);
	
	return 0;

}
Exemple #14
0
		Pattern::Pattern(const string filename)
			: _filename(filename)
		{
			//load file, or exit in case of error
			_id = arLoadPatt( _filename.c_str() );
			if ( _id < 0) {
				cerr
					<<	"Error loading pattern from file '"
					<<	_filename.c_str()
					<<	'\''
					<<	endl;
				exit(1);
			}

			_center[0] = 0.0;
			_center[1] = 0.0;
			_width = 80.0;
		}
  void ARSinglePublisher::arInit ()
  {   
    arInitCparam (&cam_param_);

    ROS_INFO ("*** Camera Parameter ***");
    arParamDisp (&cam_param_);

    // load pattern file
    ROS_INFO ("Loading pattern");
    patt_id_ = arLoadPatt (pattern_filename_);
    if (patt_id_ < 0)
    {
      ROS_ERROR ("Pattern file load error: %s", pattern_filename_);
      ROS_BREAK ();
    }

    sz_ = cvSize (cam_param_.xsize, cam_param_.ysize);
    capture_ = cvCreateImage (sz_, IPL_DEPTH_8U, 4);
  }
Exemple #16
0
/* set up the application parameters - read in from command line*/
static int init(void)
{
    char     cparaname[256];
    char     pattname[256];
    ARParam  wparam;

    strcpy( cparaname, "Data/camera_para.dat" );
    strcpy( pattname,  "Data/patt.hiro" );
    
    /* open the video path */
    if( arVideoOpen( vconf ) < 0 ) exit(0);
    /* find the size of the window */
    if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
    printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);

    /* set the initial camera parameters */
    if( arParamLoad(cparaname, 1, &wparam) < 0 ) {
       printf("Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    printf("*** Camera Parameter ***\n");
    arParamDisp( &cparam );

    /* open the graphics window */
    argInit( &cparam, 2.0, 0, 2, 1, 0 );

    if( (target_id = arLoadPatt(pattname)) < 0 ) {
        printf("Target pattern load error!!\n");
        exit(0);
    }

    arDebug = 0;

    return 0;
}
Exemple #17
0
int main(int argc, char **argv)
{
    ARUint8 *dataPtr;

    //
    // Camera configuration.
    //
#ifdef _WIN32
    char			*vconf = "Data\\WDM_camera_flipV.xml";
#else
    char			*vconf = "";
#endif

    int             count = 0;

   // char           *cparam_name    = "../calib_camera2/newparam.dat";

    char path[100];
    char cparam_name[100];
    char* cur_filename;
   
    if (argc < 2) {
        fprintf(stderr,"provide a jpeg file name\n");
        return;
    }
    

    int one = 1;
    //glutInit(&one,argv);


    cur_filename = argv[1];
    frame_ind = atoi(argv[3]);

    if (argc > 2) {
        sprintf(path,"%s/", argv[2]);
    } else {
        sprintf(path, "");
    }

    fprintf(stderr,"%d %s,\n", argc, cur_filename);

    /// make this get an image with curl
	dataPtr	    = loadImage(cur_filename,&xsize,&ysize);

	ARParam  wparam;

    sprintf(cparam_name,"%s%s",path,"camera_para.dat");
    fprintf(stderr,"%s\n", cparam_name);

    /* set the initial camera parameters */
    if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
    //if( arParamLoad("camera_para.dat", 1, &wparam) < 0 ) {
        fprintf(stderr,"Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    //fprintf(stderr,"*** Camera Parameter ***\n");
    //arParamDisp( &cparam );

    int patt_id;
    char buffer[100];
    
    sprintf(buffer,"%spatt.hiro",path);
    if( (patt_id=arLoadPatt(buffer)) < 0 ) {
        fprintf(stderr,"pattern load error !!\n");
        exit(0);
    }
   fprintf(stderr,"patt.hiro %d\n", patt_id);

    sprintf(buffer,"%spatt.sample1",path);
    if( (patt_id=arLoadPatt(buffer)) < 0 ) {
        fprintf(stderr,"pattern load error !!\n");
        exit(0);
    }
   fprintf(stderr,"patt.sample1 %d\n", patt_id);

    sprintf(buffer,"%spatt.sample2",path);
    if( (patt_id=arLoadPatt(buffer)) < 0 ) {
        fprintf(stderr,"pattern load error !!\n");
        exit(0);
    }
   fprintf(stderr,"patt.sample2 %d\n", patt_id);


    sprintf(buffer,"%spatt.kanji",path);
    if( (patt_id=arLoadPatt(buffer)) < 0 ) {
        fprintf(stderr,"pattern load error !!\n");
        exit(0);
    }
   fprintf(stderr,"patt.kanji %d\n", patt_id);


#if 0
	fprintf(stderr,"xysize %d %d\n\
cparam %g\t%g\t%g\t%g\n \
mat\n \
%g\t%g\t%g\t%g\n \
%g\t%g\t%g\t%g\n \
%g\t%g\t%g\t%g\n", 
		cparam.xsize, cparam.ysize,
		cparam.dist_factor[0], cparam.dist_factor[1], cparam.dist_factor[2], cparam.dist_factor[3], 
		cparam.mat[0][0], cparam.mat[0][1], cparam.mat[0][2], cparam.mat[0][3], 	
		cparam.mat[1][0], cparam.mat[1][1], cparam.mat[1][2], cparam.mat[1][3], 	
		cparam.mat[2][0], cparam.mat[2][1], cparam.mat[2][2], cparam.mat[2][3]	
		);
#endif

    /* open the graphics window */
    //argInit( &cparam, 1.0, 0, 0, 0, 0 );

    //printf("%s,\t\n",cur_filename);
	findMarkers(dataPtr);

    argCleanup();
}
Exemple #18
0
//========
// 初期化
//========
bool cARTK::initialize( void )
{
	const char	*szCameraParamFName = "../Data/camera_para.dat";
	const char	*szPattFName  = "../Data/patt.00";
#ifdef _WIN32
	char		*szVConfFName = "../Data/WDM_camera_flipV.xml";
#else
	char		*szVConfFName = "";
#endif

	ARParam			sCamParamTemp;
	int				iCamImgSizeX,
					iCamImgSizeY;

	// カメラデバイスのオープン
	if( arVideoOpen( szVConfFName ) < 0 )
	{
		ErrorMessage( "Unable to open connection to camera.\n" );
		return false;
	}

	// カメラ画像のサイズを取得
	if( arVideoInqSize( &iCamImgSizeX, &iCamImgSizeY ) < 0 ) return false;

	// カメラパラメータファイルの読込み
	if( arParamLoad( szCameraParamFName, 1, &sCamParamTemp ) < 0 )
	{
		ErrorMessage( "Error loading parameter file for camera.\n" );
		return false;
	}

	// カメラパラメータのサイズ部分を変更
	arParamChangeSize( &sCamParamTemp, iCamImgSizeX, iCamImgSizeY, &m_sCameraParam );

	// ライブラリ内のカメラパラメータの初期化
	arInitCparam( &m_sCameraParam );

	// カメラ画像のキャプチャを開始
	if( arVideoCapStart() != 0 )
	{
		ErrorMessage( "Unable to begin camera data capture.\n" );
		return false;
	}

	// マーカーパターンファイルの読込み
    if( (m_iPattID = arLoadPatt( szPattFName )) < 0 )
    {
		ErrorMessage( "Pattern file load error !!\n" );
		return false;
    }

	m_uiARTImageSize = sizeof(ARUint8) * iCamImgSizeX * iCamImgSizeY * 3;
	m_pARTImage = (ARUint8 *)malloc( m_uiARTImageSize );
	memset( m_pARTImage, 0, m_uiARTImageSize );

	m_dViewScaleFactor = 0.16;
	m_dPattWidth = 40.0;
	m_bFirstTime = true;

	return true;
}
Exemple #19
0
int main(int argc, char **argv)
{
	int one = 1;
	glutInit(&one,argv);
	init();
	
	cur_filename = argv[1];

	fprintf(stderr,"%d %s,\n", argc, cur_filename);
	fprintf(stdout,"%s,\t",cur_filename);

	if (argc > 2) {
		fprintf(stderr,"showing graphics\n");
		singleLoop = 0;	
	}

	////

	dataPtr	    = loadImage(cur_filename);


	///
	ARParam  wparam;
	
    /* open the video path */
    //if( arVideoOpen( vconf ) < 0 ) exit(0);
    /* find the size of the window */
    //if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
    //fprintf(stderr,"Image size (x,y) = (%d,%d)\n", xsize, image->rows);

    /* set the initial camera parameters */
    if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
        fprintf(stderr,"Camera parameter load error !!\n");
        exit(0);
    }
    arParamChangeSize( &wparam, xsize, ysize, &cparam );
    arInitCparam( &cparam );
    //fprintf(stderr,"*** Camera Parameter ***\n");
    //arParamDisp( &cparam );

    if( (patt_id=arLoadPatt(patt_name)) < 0 ) {
        fprintf(stderr,"pattern load error !!\n");
        exit(0);
    }

#if 0

	fprintf(stderr,"xysize %d %d\n\
cparam %g\t%g\t%g\t%g\n \
mat\n \
%g\t%g\t%g\t%g\n \
%g\t%g\t%g\t%g\n \
%g\t%g\t%g\t%g\n", 
		cparam.xsize, cparam.ysize,
		cparam.dist_factor[0], cparam.dist_factor[1], cparam.dist_factor[2], cparam.dist_factor[3], 
		cparam.mat[0][0], cparam.mat[0][1], cparam.mat[0][2], cparam.mat[0][3], 	
		cparam.mat[1][0], cparam.mat[1][1], cparam.mat[1][2], cparam.mat[1][3], 	
		cparam.mat[2][0], cparam.mat[2][1], cparam.mat[2][2], cparam.mat[2][3]	
		);
#endif


    /* open the graphics window */
    argInit( &cparam, 1.0, 0, 0, 0, 0 );
	///



    //arVideoCapStart();

	findMarkers();



	if (singleLoop) {
		//mainLoop();
	} else {
    	argMainLoop( NULL, NULL /*keyEvent*/, mainLoop );
	}
}
Exemple #20
0
ObjectData_T *read_ObjData( char *name, int *objectnum, char *pathtofile )
{
    FILE          *fp;
    ObjectData_T  *object;
    char           buf[256], buf1[256], buf2[256], ptf[256];
    int            i;

	post("Opening Data File %s\n",name);

    if( (fp=fopen(name, "r")) == NULL ) {
		post("Can't find the file - quitting \n");
		return(0);
	}

    get_buff(buf, 256, fp);
    if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}

	post("About to load %d Markers\n",*objectnum);

    object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
    if( object == NULL ) return(0);

    for( i = 0; i < *objectnum; i++ ) {
		memset(&buf2[0], 0, sizeof(buf2));
		object[i].visible = 0;   
		
		get_buff(buf, 256, fp);
        if( sscanf(buf, "%s", object[i].name) != 1 ) {
			
            fclose(fp); free(object); return(0);
        }
		post("Marker %s from oulet %d \n", object[i].name, i+1);

        get_buff(buf, 256, fp);

      //converted to get the whole line path
		if( sscanf(buf, "%[^\n]", buf1) != 1 ) {
		fclose(fp); free(object); return(0);
		}
		
		strcpy(ptf, pathtofile);
		strcat(ptf, buf1);
		strcpy(buf2, ptf);
		if( (object[i].id = arLoadPatt(buf2)) < 0 ){
			fclose(fp); free(object); return(0);
		}

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
            fclose(fp); free(object); return(0);
        }

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf %lf", &object[i].marker_center[0],
            &object[i].marker_center[1]) != 2 ) {
            fclose(fp); free(object); return(0);
        }
        
    }

    fclose(fp);

    return( object );
}
/*
* Class:     com_clab_artoolkit_port_JARToolkit
* Method:    JARLoadPattern
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_net_sourceforge_jartoolkit_core_JARToolKit_loadPattern(JNIEnv *env, jobject, jstring jfilename)
{
	const char *filename = env->GetStringUTFChars(jfilename, 0);

	return arLoadPatt((char *)filename);
}
AR_DLL_API ARMultiMarkerInfoT *arMultiReadConfigFile( const char *filename )
{
    FILE *fp=fopen(filename,"r");
    if(fp == NULL){
        return NULL;
    }

    char buf[256];
    get_buff(buf, 256, fp);

    int num;
    if( sscanf(buf, "%d", &num) != 1 ) {
        fclose(fp); return NULL;
    }

    ARMultiEachMarkerInfoT *marker;
    ARMultiMarkerInfoT     *marker_info;
    arMalloc(marker,ARMultiEachMarkerInfoT,num);

    std::string dir=getdir(filename);

    for(int i = 0; i < num; i++ ) {
        get_buff(buf, 256, fp);
        char buf1[256];
        if( sscanf(buf, "%s", buf1) != 1 ) {
            fclose(fp); free(marker); return NULL;
        }
        if( (marker[i].patt_id = arLoadPatt((dir+"/"+buf1).c_str())) < 0 ) {
            fclose(fp); free(marker); return NULL;
        }

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf", &marker[i].width) != 1 ) {
            fclose(fp); free(marker); return NULL;
        }

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf %lf", &marker[i].center[0], &marker[i].center[1]) != 2 ) {
            fclose(fp); free(marker); return NULL;
        }

        for(int j = 0; j < 3; j++ ) {
            get_buff(buf, 256, fp);
            if( sscanf(buf, "%lf %lf %lf %lf", &marker[i].trans[j][0],
                       &marker[i].trans[j][1], &marker[i].trans[j][2],
                       &marker[i].trans[j][3]) != 4 ) {
                fclose(fp); free(marker); return NULL;
            }
        }
        arUtilMatInv( marker[i].trans, marker[i].itrans );

        double wpos3d[4][2];
        wpos3d[0][0] = marker[i].center[0] - marker[i].width/2.0;
        wpos3d[0][1] = marker[i].center[1] + marker[i].width/2.0;
        wpos3d[1][0] = marker[i].center[0] + marker[i].width/2.0;
        wpos3d[1][1] = marker[i].center[1] + marker[i].width/2.0;
        wpos3d[2][0] = marker[i].center[0] + marker[i].width/2.0;
        wpos3d[2][1] = marker[i].center[1] - marker[i].width/2.0;
        wpos3d[3][0] = marker[i].center[0] - marker[i].width/2.0;
        wpos3d[3][1] = marker[i].center[1] - marker[i].width/2.0;
        for(int j = 0; j < 4; j++ ) {
            marker[i].pos3d[j][0] = marker[i].trans[0][0] * wpos3d[j][0]
                                  + marker[i].trans[0][1] * wpos3d[j][1]
                                  + marker[i].trans[0][3];
            marker[i].pos3d[j][1] = marker[i].trans[1][0] * wpos3d[j][0]
                                  + marker[i].trans[1][1] * wpos3d[j][1]
                                  + marker[i].trans[1][3];
            marker[i].pos3d[j][2] = marker[i].trans[2][0] * wpos3d[j][0]
                                  + marker[i].trans[2][1] * wpos3d[j][1]
                                  + marker[i].trans[2][3];
        }
    }

    fclose(fp);

    marker_info = (ARMultiMarkerInfoT *)malloc( sizeof(ARMultiMarkerInfoT) );
    if( marker_info == NULL ) {free(marker); return NULL;}
    marker_info->marker     = marker;
    marker_info->marker_num = num;
    marker_info->prevF      = 0;

    return marker_info;
}
Exemple #23
0
//========
// 初期化
//========
bool cARTK::initialize( void )
{
	const char	*szCameraParamFName = "Data/camera_para.dat";
#ifdef _WIN32
	char		*szVConfFName = "Data/WDM_camera_flipV.xml";
#else
	char		*vconf = "";
#endif

	ARParam			sCamParamTemp;
	int				iCamImgSizeX,
					iCamImgSizeY;

	// カメラデバイスのオープン
	if( arVideoOpen( szVConfFName ) < 0 )
	{
		ErrorMessage( "Unable to open connection to camera.\n" );
		return false;
	}

	// カメラ画像のサイズを取得
	if( arVideoInqSize( &iCamImgSizeX, &iCamImgSizeY ) < 0 ) return false;

	// カメラパラメータファイルの読込み
	if( arParamLoad( szCameraParamFName, 1, &sCamParamTemp ) < 0 )
	{
		ErrorMessage( "Error loading parameter file for camera.\n" );
		return false;
	}

	// カメラパラメータのサイズ部分を変更
	arParamChangeSize( &sCamParamTemp, iCamImgSizeX, iCamImgSizeY, &m_sCameraParam );

	// ライブラリ内のカメラパラメータの初期化
	arInitCparam( &m_sCameraParam );

	// NyARTransMatの初期化
	m_pNyARInst = nyar_NyARTransMat_O2_create( &m_sCameraParam );

	// カメラ画像のキャプチャを開始
	if( arVideoCapStart() != 0 )
	{
		ErrorMessage( "Unable to begin camera data capture.\n" );
		return false;
	}

	// マーカーパターンファイルの読込み
	for( int i = 0 ; i < ARMK_MAXNUM ; i++ )
	{
		if( (m_sMarkerInfo[i].iPattID = arLoadPatt( g_szPattFName[i] )) < 0 )
		{
			ErrorMessage( "Pattern file load error !!\n" );
			return false;
		}

		m_sMarkerInfo[i].dWidth = g_dPattWidth[i];
		m_sMarkerInfo[i].dCenterPos[0] = m_sMarkerInfo[i].dCenterPos[1] = 0.0f;
		m_sMarkerInfo[i].bVisible = false;
	}

	// ちょっとずらす
	m_sMarkerInfo[1].dCenterPos[0] =  0.0f;
	m_sMarkerInfo[1].dCenterPos[1] = 30.0f;

	m_iThreshold = 120;
	m_dViewScaleFactor = 0.16;

	return true;
}
Exemple #24
0
/*
 * Class:     net_towerdefender_image_ARToolkit
 * Method:    addObject
 * Signature: (ILedu/dhbw/andar/ARObject;Ljava/lang/String;D[D)V
 */
JNIEXPORT void JNICALL Java_net_towerdefender_image_ARToolkit_addObject(
		JNIEnv * env, jobject artoolkit, jint name, jobject obj,
		jstring patternFile, jdouble width, jdoubleArray center) {
	Object* newObject;
	jdouble* centerArr;
	centerArr = (*env)->GetDoubleArrayElements(env, center, NULL);
	const char *cPatternFile = (*env)->GetStringUTFChars(env, patternFile,
			NULL);
	if (centerArr == NULL) {
		//could not retrieve the java array
		jclass exc = (*env)->FindClass(env,
				"net/towerdefender/exceptions/ARException");
		if (exc != NULL)
			(*env)->ThrowNew(env, exc,
					"could not retrieve array of the marker center in native code.");
	}
	if ((newObject = (Object *) malloc(sizeof(Object))) == NULL) {
		//something went wrong with allocating -> throw error
		jclass exc = (*env)->FindClass(env,
				"net/towerdefender/exceptions/ARException");
		if (exc != NULL)
			(*env)->ThrowNew(env, exc,
					"could not allocate memory for new object.");
	} else {
		//ok object allocated, now fill the struct with data
#ifdef DEBUG_LOGGING
		__android_log_print(ANDROID_LOG_INFO,"AR native","registering object with name %d", name);
#endif
		newObject->name = (int) name;
		newObject->marker_width = (double) width;
		newObject->contF = 0;
		newObject->marker_center[0] = (double) centerArr[0];
		newObject->marker_center[1] = (double) centerArr[1];
		newObject->objref = (*env)->NewGlobalRef(env, obj);
		//search the list of pattern IDs for a pattern matching the given filename
		//this is needed as the native library doesn't get unloaded after the Java application finished
		//and multiple invocations of arLoadPatt with the same pattern file will result in incorrect IDs
		if ((newObject->id = getPatternIDFromList(cPatternFile)) < 0) {
			if ((newObject->id = arLoadPatt(cPatternFile)) < 0) {
				//failed to read the pattern file
				//release the object and throw an exception
				free(newObject);
				jclass exc = (*env)->FindClass(env,
						"net/towerdefender/exceptions/ARException");
				if (exc != NULL)
					(*env)->ThrowNew(env, exc,
							"could not read pattern file for object.");
			} else {
#ifdef DEBUG_LOGGING
				__android_log_print(ANDROID_LOG_INFO,"AR native","loaded marker with ID %d from file: %s", newObject->id, cPatternFile);
#endif
				//add object to the list
				list_append(&objects, newObject);
				patternID* newPatternID = (patternID *) malloc(
						sizeof(patternID));
				if (newPatternID != NULL) {
					newPatternID->filename = strdup(cPatternFile);
					newPatternID->id = newObject->id;
					list_append(patternIDs, newPatternID);
				}
			}
		} else {
#ifdef DEBUG_LOGGING
			__android_log_print(ANDROID_LOG_INFO,"AR native","loaded marker with ID %d from cached pattern ID", newObject->id, cPatternFile);
#endif
			//add object to the list
			list_append(&objects, newObject);
		}
	}
	//release the marker center array
	(*env)->ReleaseDoubleArrayElements(env, center, centerArr, 0);
	(*env)->ReleaseStringUTFChars(env, patternFile, cPatternFile);
}
Exemple #25
0
int ActuatorARTKSM::actuatorReadFile(){
	FILE          *fp;
	char		  buf[256],buf1[256],fileDAT[256];

	//--------------------------------------------------------------------------
	// Open the ActuatorARTKSM Configuration file
	//--------------------------------------------------------------------------
	printf("\n --------------------------------------------------------------------------");
	if( (fp=fopen(this->configFilename,"r")) == NULL) {
		printf("\n Error on opening %s !! ",this->configFilename);
		return  -1;
	}
	printf("\n Opening file %s ,  ARTKSM Actuator", this->configFilename);
	printf("\n --------------------------------------------------------------------------");

	//--------------------------------------------------------------------------
	// READ THE Actuator Name
	//--------------------------------------------------------------------------
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s", &this->name) != 1) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1;	}
	printf("\n Actuator name: %s", this->name);

	//--------------------------------------------------------------------------
	// READ THE MARKER CONFIGURATION
	//--------------------------------------------------------------------------
	// Marker that defines the actuator
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s", &buf1) != 1) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1;	}
	if ((this->patternNumber = arLoadPatt(buf1)) < 0) { fclose(fp);  return(0);	}
	printf("\n Using marker: %s, id: %d", buf1, this->patternNumber); 
	// Marker Width
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%lf", &this->markerWidth) != 1) { printf("\n Check %s file format", this->configFilename);fclose(fp); return -1;  }
	// Marker Center
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%lf %lf", &this->markerCenter[0], &this->markerCenter[1]) != 2) {
			printf("\n Check %s file format", this->configFilename); fclose(fp); return(0);  }
	printf(" W: %3.2f, Center(%3.2f,%3.2f)", this->markerWidth , this->markerCenter[0], this->markerCenter[1]);
	// Marker cover (USE_DEFAULT to get default marker cover / NO_COVER to don't use a marker cover)
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s %s", &buf1, &fileDAT) != 2) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }
	
	if( strcmp(buf1, "NO_COVER") == 0){
		this->cover = 0;
		printf("\n Actuator Marker without cover.");
	}
	else{

		if ( strcmp(buf1, "USE_DEFAULT") == 0) { 
			this->cover = (*myArpe).myGenericItens.markCover;
			printf("\n Using Default Cover ");
		}
		else{
			if (strcmp(buf1, "VRML") == 0) {
				//VRML Object
				iVrml *c = new iVrml();
				(*c).modelType = 1;
				(*c).vrmlID = arVrmlLoadFile(fileDAT); 
				if ((*c).vrmlID < 0) {
					printf("\n Error on Marker Base Cover %s file or on VRML file (%d)",fileDAT,(*c).vrmlID);
					this->cover = 0;
				} else { 
					printf("\n Cover object VRML id: %d ", (*c).vrmlID); 
					this->cover = c;}
				
			} else {
				printf("\n type not yet coded!!! Patience! ");
			}
		}
	}
	//--------------------------------------------------------------------------
	// READ THE Symbolic
	//--------------------------------------------------------------------------
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s %s", &buf1, &fileDAT) != 2) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }
	if (strcmp(buf1, "VRML") == 0) {
		//VRML Object
		iVrml *s = new iVrml();
		(*s).modelType = 1;
		(*s).vrmlID = arVrmlLoadFile(fileDAT); 
		if ((*s).vrmlID < 0) {
			printf("\n Error on Symbolic object %s file or on VRML file (%d)",fileDAT,(*s).vrmlID);
			this->symbol = 0;
		} else { 
			printf("\n Symbolic object VRML id: %d ", (*s).vrmlID); 
			this->symbol = s;}
	} else {
		printf("\n type not yet coded!!! Patience! ");
	}

	//--------------------------------------------------------------------------
	// READ Point were the action occors on the ARTSM Actuator
	//--------------------------------------------------------------------------
	// Point model
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s %s", &buf1, &fileDAT) != 2) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }

	if ( strcmp(buf1, "DEFAULT_IPOINT") == 0) { 
		this->interactionPoint = (*myArpe).myGenericItens.holding;
		printf("\n Using Default Interaction Point Representation.");
	}
	else{

		if (strcmp(buf1, "VRML") == 0) {
			//VRML Object
			iVrml *ip = new iVrml();
			(*ip).modelType = 1;
			(*ip).vrmlID = arVrmlLoadFile(fileDAT); 
			printf("\n Point model object VRML id: %d ", (*ip).vrmlID);
			if ((*ip).vrmlID < 0) {
				printf("\n Error on Point model object %s file or on VRML file (%d)",fileDAT,(*ip).vrmlID);
				this->interactionPoint = 0;
			} else { 
				printf("\n Point model object VRML id: %d ", (*ip).vrmlID); 
				this->interactionPoint = ip;}
			if ((*ip).vrmlID < 0) { fclose(fp); return(0); }
			
		} else {
			printf("\n type not yet coded!!! Patience! ");
		}
	}
	// Translation (x,y,z) (mm)
	getBuff(buf, 256, fp);
	if( sscanf(buf, "%lf %lf %lf",	&this->ipTra[0], &this->ipTra[1], &this->ipTra[2]) != 3 ) {
			printf("\n Check %s file format", this->configFilename);fclose(fp); return -1;  }
	// Action radius of the point
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%lf", &this->distCollision) != 1) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }
	printf("\n Point position from center (%3.2f,%3.2f,%3.2f), radius: %3.2f", 
		this->ipTra[0], this->ipTra[1], this->ipTra[2], this->distCollision);

	fclose(fp);
	
	return 0;
}
ARMultiMarkerInfoT*
Tracker::arMultiReadConfigFile(const char *filename) {
    FILE *fp;
    ARMultiEachMarkerInfoT *marker;
    ARMultiMarkerInfoT *marker_info;
    ARFloat wpos3d[4][2];
    char buf[256], buf1[256];
    int num;
    int i, j;

    setlocale(LC_NUMERIC, "C");

    if ((fp = fopen(filename, "r")) == NULL)
        return NULL;

    get_buff(buf, 256, fp);
    if (sscanf(buf, "%d", &num) != 1) {
        fclose(fp);
        return NULL;
    }

    arMalloc(marker, ARMultiEachMarkerInfoT, num);

    for (i = 0; i < num; i++) {
        get_buff(buf, 256, fp);
        if (sscanf(buf, "%s", buf1) != 1) {
            fclose(fp);
            free(marker);
            return NULL;
        }
        // Added by Daniel: if the markername is an integer number
        // we directly interprete this as the marker id (used for
        // id-based markers)
        if (isNumber(buf1))
            marker[i].patt_id = atoi(buf1);
        else if ((marker[i].patt_id = arLoadPatt(buf1)) < 0) {
            fclose(fp);
            free(marker);
            return NULL;
        }

        get_buff(buf, 256, fp);
#ifdef _USE_DOUBLE_
        if( sscanf(buf, "%lf", &marker[i].width) != 1 ) {
#else
        if (sscanf(buf, "%f", &marker[i].width) != 1) {
#endif
            fclose(fp);
            free(marker);
            return NULL;
        }

        get_buff(buf, 256, fp);
#ifdef _USE_DOUBLE_
        if( sscanf(buf, "%lf %lf", &marker[i].center[0], &marker[i].center[1]) != 2 ) {
#else
        if (sscanf(buf, "%f %f", &marker[i].center[0], &marker[i].center[1]) != 2) {
#endif
            fclose(fp);
            free(marker);
            return NULL;
        }

        for (j = 0; j < 3; j++) {
            get_buff(buf, 256, fp);
            if (sscanf(buf,
#ifdef _USE_DOUBLE_
                       "%lf %lf %lf %lf",
#else
                       "%f %f %f %f",
#endif
                       &marker[i].trans[j][0], &marker[i].trans[j][1], &marker[i].trans[j][2], &marker[i].trans[j][3])
                    != 4) {
                fclose(fp);
                free(marker);
                return NULL;
            }
        }
        arUtilMatInv(marker[i].trans, marker[i].itrans);

        wpos3d[0][0] = marker[i].center[0] - marker[i].width * 0.5f;
        wpos3d[0][1] = marker[i].center[1] + marker[i].width * 0.5f;
        wpos3d[1][0] = marker[i].center[0] + marker[i].width * 0.5f;
        wpos3d[1][1] = marker[i].center[1] + marker[i].width * 0.5f;
        wpos3d[2][0] = marker[i].center[0] + marker[i].width * 0.5f;
        wpos3d[2][1] = marker[i].center[1] - marker[i].width * 0.5f;
        wpos3d[3][0] = marker[i].center[0] - marker[i].width * 0.5f;
        wpos3d[3][1] = marker[i].center[1] - marker[i].width * 0.5f;
        for (j = 0; j < 4; j++) {
            marker[i].pos3d[j][0] = marker[i].trans[0][0] * wpos3d[j][0] + marker[i].trans[0][1] * wpos3d[j][1]
                                    + marker[i].trans[0][3];
            marker[i].pos3d[j][1] = marker[i].trans[1][0] * wpos3d[j][0] + marker[i].trans[1][1] * wpos3d[j][1]
                                    + marker[i].trans[1][3];
            marker[i].pos3d[j][2] = marker[i].trans[2][0] * wpos3d[j][0] + marker[i].trans[2][1] * wpos3d[j][1]
                                    + marker[i].trans[2][3];
        }
    }

    fclose(fp);
    setlocale(LC_NUMERIC, "C");

    marker_info = (ARMultiMarkerInfoT *) malloc(sizeof(ARMultiMarkerInfoT));
    if (marker_info == NULL) {
        free(marker);
        return NULL;
    }
    marker_info->marker = marker;
    marker_info->marker_num = num;
    marker_info->prevF = 0;

    return marker_info;
}


}  // namespace ARToolKitPlus